HP C Programmer's Guide (92434-90009)

18 Chapter2
Storage and Alignment Comparisons
Alignment Rules
NOTE
In NOPADDING alignment mode, the alignment boundary is 1 byte in all
cases except where bitfields are used.
HPUX_WORD/DOMAIN_WORD Alignments
For HPUX_WORD and DOMAIN_WORD alignments, all structure and union types are 2-byte
aligned. Member types larger than 2 bytes are aligned on a 2-byte boundary. Padding is
performed as necessary to reach a resulting structure or union size which is a multiple of 2
bytes.
For example:
struct st {
char c;
long l;
char d;
short b;
int i[2];
}s;
Compiling with the +m option to show the offsets of the identifiers, you will get the
following output. Offsets are given as "byte-offset" @ "bit-offset" in hexadecimal.
Identifier Class Type Address
---
s ext def struct st
c member char 0x0 @ 0x0
l member long int 0x2 @ 0x0
d member char 0x6 @ 0x0
b member short int 0x8 @ 0x0
i member ints [2] 0xa @ 0x0
The resulting size of the structure is 18 bytes, with the alignment of 2 bytes, as illustrated
long long 8 2 8 4 8
pointer 4 2 4 4 4
long pointer 8 2 4 4 4
float 4 2 4 4 4
double 8 2 8 4 8
long double 16 2 8 4 8
arrays Follows alignment of array type inside a structure or union.
struct, union Follows alignment of its most restricted member.
Table 2-3. Aligning Structure or Union Members
Data Type Size
(bytes)
HPUX_WORD
DOMAIN_WORD
HPUX_NATURAL
DOMAIN_NATUR
AL
HPUX_
NATURAL_S
500
NATURAL