HP C/iX Reference Manual (31506-90011)
36 Chapter3
Data Types and Declarations
Structure and Union Specifiers
Unions are like structures except that all members of a union have a zero offset from the
beginning of the union. In other words, the members overlap. Unions are a way to store
different type of objects in the same memory location.
A declarator for a member of a structure or union may occupy a specified number of bits.
This is done by following the declarator with a colon and a constant non-negative integral
expression. The value of the expression indicates the number of bits to be used to hold the
member. This type of member is called a bit-field. Only integral type specifiers are allowed
for bit-field declarators.
In structures, bit-fields are placed into storage locations from the most significant bits to
the least significant bits. Bit-fields that follow one another are packed into the same
storage words, if possible. If a bit-field will not fit into the current storage location, it is put
into the beginning of the next location and the current location is padded with an unnamed
field.
A colon followed by an integer constant expression indicates that the compiler should
create an unnamed bit-field at that location. In addition, a colon followed by a zero
indicates that the current location is full and that the next bit-field should begin at the
start of the next storage location. Refer to chapter 9 for the treatment of the sign for
bit-fields. Although bit-fields are permitted in unions (ANSI mode only), they are just like
any other members of the union in that they have a zero offset from the beginning of the
union. That is, they are not packed into the same word, as in the case of structures. The
special cases of unnamed bit-fields and unnamed bit-fields of length zero behave
differently with unions; they are simply unnamed members that cannot be assigned to.
The unary address operator (&) may not be applied to bit-fields. This implies that there
cannot be pointers to bit-fields nor can there be arrays of bit-fields.
The largest bit-field is the length of an int (refer to chapter 9 for exact sizes). Bit-fields do
not straddle a word boundary.