HP C Programmer's Guide (92434-90009)

Chapter 2 21
Storage and Alignment Comparisons
Alignment Rules
Figure 2-3. Example of NOPADDING Alignment for Structure s1
Note that if a member of a structure or union has been declared previously under a
different alignment mode, it will retain its original alignment which may not be byte
alignment. The NOPADDING alignment will not override the alignment of the member, so
there may be some padding done within the structure, and the structure may be greater
than byte aligned.
Refer to the section "Aligning Structures Between Architectures" below for examples on on
structure alignment for different systems.
Alignment of Bit-Fields
The alignment modes for bit-fields are grouped differently than they are for the other
types. The three groups are:
HPUX_NATURAL/HPUX_NATURAL_S500
DOMAIN_WORD/DOMAIN_NATURAL/NATURAL/NOPADDING
HPUX_WORD (combination of the previous two)
HPUX_NATURAL/HPUX_NATURAL_S500 Alignments
For HPUX_NATURAL and HPUX_NATURAL_S500 alignments, no bit-field can cross a "natural"
boundary. A bit-field that immediately follows another bit-field is packed into adjacent bits,
unless the second bit-field crosses a natural boundary according to its type. For example:
struct {
int a:5;
int b:15;
int c:17;
char :0;
char d:5;
char e:5;
} foo;
when compiled with the +m option produces:
Identifier Class Type Address
--
foo ext def struct
a member int 0x0 @ 0x0
b member int 0x0 @ 0x5
c member int 0x4 @ 0x0
<NULL_SYMBOL> member char 0x7 @ 0x0