HP C Programmer's Guide (92434-90009)

16 Chapter2
Storage and Alignment Comparisons
Alignment Rules
Alignment Rules
This discussion of alignment rules divides them into sections on scalar types, arrays,
structures and unions, bit-fields, and typedefs.
Alignment of Scalar Types
Scalar types are integral types, floating types, and pointer types. Alignment of scalar types
that are not part of a structure, union, or typedef declaration are not affected by the
alignment mode. Therefore, they are aligned the same way in all alignment modes.
*8 bytes on DOMAIN
NOTE
Except for the HPUX_NATURAL and DOMAIN_NATURAL modes, the alignment of
scalar types inside a structure or union may differ. (See the section
"Alignment of Structures and Unions" below.) Also, a type that is defined via
a typedef to any of the scalar types below may have a different alignment.
(See the section "Alignment of Typedefs.")
Alignment of Arrays
An array is aligned according to its element type. For example, a double array is aligned
on an 8-byte boundary; and a float array within a struct is aligned on a 4-byte boundary.
Alignment of array elements is not affected by the alignment mode, unless the array itself
Table 2-2. Aligning Scalar Types
Data Type Size (bytes) Alignment
(bytes)
char, signed char, unsigned char, char enum 11
short, unsigned short, signed short, short enum 22
int, signed int, unsigned int, int enum 44
long, signed long, unsigned long, long enum 44
enum 44
long long 88
pointer 44
long pointer 84
float 44
double 88
long double 16* 8