|
|
This section describes the implementation-defined characteristics of structures, unions, enumerations, and bit-fields. It corresponds to section ``F.3.9 Structures, Unions, Enumerations, and Bit-Fields'' in the ANSI document.
Attempts to access a union member will always succeed. The value of the member object will be the value of the first ``n'' bytes of the union (where ``n'' is the size of the object being accessed) interpreted according to the type of the accessed member.
The Intel® 80x86 does not impose a restriction on the alignment of objects; any object can start at any address. However, for certain objects, having a particular starting address can speed up processor access.
The C compiler aligns the whole structure on a 4-byte boundary by default (see ``Pragmas''). All [4|8|10]-byte objects are aligned on a 4-byte boundary, 2-byte objects are aligned on a 2-byte boundary, while 1-byte objects are not aligned.
A ``plain'' int bit-field is treated as a signed int bit-field.
Bit-fields are allocated in an int
starting from the lowest order bit to the highest.
For example, the structure
struct { int x:10; int y:20; int z:2;} y;would be stored like
zzyyyyyyyyyyyyyyyyyyyyxxxxxxxxxx 44444444333333332222222211111111where
z
, y
, and x
represent
the bits of the corresponding bit-field,
and 1
, 2
,
3
, and 4
, represent the bits of the
corresponding bytes.
The order of allocation of bit-fields within an int is determined by the architecture of Intel processors which store the low order byte of an int at a lower address than the highest order byte in that int. For example:
A bit-field cannot straddle its storage-unit boundary, an int, which is 32 bits wide.
The values of an enumeration type are represented by an int.