HP C/iX Reference Manual (31506-90011)

48 Chapter3
Data Types and Declarations
Initialization
Initialization
An initializer is the part of a declaration that provides the initial values for the objects
being declared.
Syntax
initializer
::=
assignment-expression
{
initializer-list
}
{
initializer-list
,}
initializer-list
::=
initializer
initializer-list , initializer
Examples
wchar_t wide_message[ ]=L"x$$z";
You initialize structures as you do any other aggregate:
struct{
int i;
unsigned u:3;
unsigned v:5;
float f;
char *p;
}s[]={
{1, 07, 03, 3.5, "cats eat bats" },
{2, 2, 4, 5.0, "she said with a smile"}
};
Note that the object being declared (s) is an array of structures without a specified
dimension. The compiler counts the initializers to determine the array's dimension. In this
case, the presence of two initializers implies that the dimension of s is two. You can
initialize named bit-fields as you would any other member of the structure.
If the value used to initialize a bit-field is too large, it is truncated to fit in the bit-field.
For example, if the value 11 were used to initialize the 3-bit field u above, the actual value
of u would be 3 (the top bit is discarded).
A struct or union with automatic storage duration can also be intialized with a single
expression of the correct type.
Description
A declarator may include an initializer that specifies the initial value for the object whose
identifier is being declared.
Objects with static storage duration are initialized at load time. Objects with automatic