DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
ANSI implementation-defined behavior

Structures, unions, enumerations, and bit-fields

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.

Improper access to a union

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.

Padding and alignment of members of structures

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.

Sign of bit-fields

A ``plain'' int bit-field is treated as a signed int bit-field.

Order of allocation of bit-fields

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
   44444444333333332222222211111111
where 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:


1st byte
- low memory or address 'x'

2nd byte
- address 'x' + 1

3rd byte
- address 'x' + 2

4th byte
- address 'x' + 3

Alignment of bit-fields

A bit-field cannot straddle its storage-unit boundary, an int, which is 32 bits wide.

The type of values of an enumerated type

The values of an enumeration type are represented by an int.


Next topic: Qualifiers
Previous topic: Registers

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003