HP C A.06.05 Reference Manual
Data Types and Declarations
Initialization
Chapter 366
{1, 07, 03, 3.5, "cats eat bats" },
{2, 2, 4, 5.0, "she said with a smile"}
};
Note that the object (s), being declared, 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 initializes 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 initialized with a single
expression of the correct type.
struct SS { int y; };
extern struct SS g(void);
func()
{
struct SS z = g();
}
When initializing a union, since only one union member can be active at one time, the first
member of the union is taken to be the initialized member.
The union initialization is only available in ANSI mode.
union {
int i;
float f;
unsigned u:5;
} = { 15 };