HP C Programmer's Guide (92434-90009)

20 Chapter2
Storage and Alignment Comparisons
Alignment Rules
alignment modes, padding is done to a multiple of the alignment size.
For example, the following code:
struct {
char c;
double d;
} s1;
compiled with the +m option produces:
Identifier Class Type Address
-- -
s1 ext def struct
c member char 0x0 @ 0x0
d member double 0x4 @ 0x0
The entire structure is 4-byte aligned, with a resulting size of 12 bytes.
NATURAL Alignments
For NATURAL alignments, structures and unions are aligned on 2-, 4-, or 8-byte boundaries,
according to the strictest alignment of its members. Padding is done to a multiple of the
alignment size.
NOPADDING Alignments
For NOPADDING alignments, structure or union members are byte aligned; therefore, struct
and union types are byte aligned. This alignment mode does not cause compressed packing
where there are zero bits of padding. It only ensures that there will be no full bytes of
padding in the structure or union, unless bit-fields are used. There may be bit paddings or
even a full byte of padding between members if there are bit-fields. Refer to the section
"Alignment of Bit-Fields" for more information.
Consider the following code fragment:
#pragma HP_ALIGN NOPADDING
typedef struct s {
char c;
short s;
} s1;
s1 arr[4];
The size of s1 is 3 bytes, with 1-byte alignment. Therefore, the size of arr is 12 bytes, with
1-byte alignment. There is no padding between the individual array elements; they are all
packed on a byte boundary (see Figure 2-3. on page 21).