Whole document tree
4.19 Constructor ExpressionsGNU C supports constructor expressions. A constructor looks like a cast containing an initializer. Its value is an object of the type specified in the cast, containing the elements specified in the initializer.
Usually, the specified type is a structure. Assume that
Here is an example of constructing a
This is equivalent to writing the following:
You can also construct an array. If all the elements of the constructor are (made up of) simple constant expressions, suitable for use in initializers, then the constructor is an lvalue and can be coerced to a pointer to its first element, as shown here:
Array constructors whose elements are not simple constants are
not very useful, because the constructor is not an lvalue. There
are only two valid ways to use it: to subscript it, or initialize
an array variable with it. The former is probably slower than a
Constructor expressions for scalar types and union types are is also allowed, but then the constructor expression is equivalent to a cast. This document was generated by root on January, 30 2002 using texi2html |