Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
4 Variables and Types<br />
There are no implicit array or structure conversions. For example, an array of int cannot be implicitly<br />
converted to an array of float.<br />
When an implicit conversion is done, it is not a re-interpretation of the expression's bit pattern, but a<br />
conversion of its value to an equivalent value in the new type. For example, the integer value -5 will be<br />
converted to the floating-point value -5.0. Integer values having more bits of precision than a floating<br />
point mantissa will lose precision when converted to float.<br />
When performing implicit conversion for binary operators, there may be multiple data types to which the<br />
two operands can be converted. For example, when adding an int value to a uint value, both values can<br />
be implicitly converted to uint, float, and double. In such cases, a floating-point type is chosen if either<br />
operand has a floating-point type. Otherwise, an unsigned integer type is chosen if either operand has an<br />
unsigned integer type. Otherwise, a signed integer type is chosen. If operands can be implicitly converted<br />
to multiple data types deriving from the same base data type, the type with the smallest component size is<br />
used.<br />
The conversions in the table above are done only as indicated by other sections of this specification.<br />
4.1.11 Initializers<br />
At declaration, an initial value for an aggregate variable may be provided, specified as an equals (=)<br />
followed by an initializer. The initializer is either an assignment-expression or a list of initializers<br />
enclosed in curly braces. The grammar for the initializer is:<br />
initializer :<br />
assignment-expression<br />
{ initializer-list }<br />
{ initializer-list , }<br />
initializer-list :<br />
initializer<br />
initializer-list , initializer<br />
The assignment-expression is a normal expression except that a comma ( , ) outside parentheses is<br />
interpreted as the end of the initializer, not as the sequence operator. As explained in more detail below,<br />
this allows creation of nested initializers: The aggregate and its initializer must exactly match in terms of<br />
nesting, number of components/elements/members present at each level, and types of<br />
components/elements/members.<br />
An assignment-expression in an initializer must be either the same type as the object it initializes or be a<br />
type that can be converted to the object's type according to section 4.1.10 "Implicit Conversions". Since<br />
these include constructors, an aggregate can be initialized by either a constructor or an initializer list; an<br />
element in an initializer list can be a constructor.<br />
If an initializer is a list of initializers enclosed in curly braces, the variable being declared must be a<br />
vector, a matrix, an array, or a structure.<br />
int i = { 1 };<br />
// illegal, i is not an aggregate<br />
32