HP C Programmer's Guide (92434-90009)

Chapter 2 17
Storage and Alignment Comparisons
Alignment Rules
is a member of a structure or union. An array that is a member of a structure or union is
aligned according to the rules for structure or union member alignment (see the section
"Alignment of Structures and Unions" below for more information.)
An array's size is computed as:
(size of array element type) × (number of elements)
For instance, the array declared below is 400 bytes (4 × 100) long:
int arr[100];
The size of the array element type is 4 bytes and the number of elements is 100.
Alignment of Structures and Unions
In a structure, each member is allocated sequentially at the next alignment boundary
corresponding to its type. Therefore, the structure might be padded internally if its
members' types have different alignment requirements. In a union, all members are
allocated starting at the same memory location. Both structures and unions can have
padding at the end, in order to make the size a multiple of the alignment.
NOTE
These rules are
not
true if the member type has been previously declared
under another alignment mode. The member type will retain its original
alignment, overriding other modes in effect. See the section "The HP_ALIGN
Pragma" below for information on controlling alignment of structures and
unions.
Table on page 17 lists the alignments for structure and union members.
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
char, signed
char, unsigned
char, char enum
11111
short, unsigned
short, signed
short, short
enum
22222
int, signed int,
unsigned int, int
enum
42444
long, signed
long, unsigned
long, long enum
42444
enum 4 2 4 4 4