HP C Programmer's Guide (92434-90009)

26 Chapter2
Storage and Alignment Comparisons
The HP_ALIGN Pragma
The HP_ALIGN Pragma
The HP_ALIGN pragma controls data storage allocation and alignment of structures,
unions, and type definitions, using typedefs. It enables you to control the alignment mode
when allocating storage space for data. It is especially important when used to control the
allocation of binary data that is transmitted among machines having different hardware
architectures.
The HP_ALIGN pragma takes a parameter indicating which alignment mode to use. Not all
modes are available on all HP platforms; the NATURAL alignment mode is the most widely
available on HP-UX. This mode is the recommended standard.
The syntax for the HP_ALIGN pragma is:
[#pragma HP_ALIGN
align_mode
[PUSH]]
[#pragma HP_ALIGN POP]
where
align_mode
is one of the following:
HPUX_WORD This is the Series 300/400 default alignment mode.
HPUX_NATURAL_S500 This is the Series 500 default alignment mode.
HPUX_NATURAL This is the HP 9000 Series 700/800 and HP 3000 Series 900 systems
default alignment mode.
NATURAL This mode provides a consistent alignment scheme across HP
architectures.
DOMAIN_WORD This is the default word alignment mode on HP Apollo architecture.
DOMAIN_NATURAL This is the default natural alignment mode on HP Apollo architecture.
NOPADDING This causes all structures and union members that are not bit-fields to be
packed on a byte boundary. It does not cause compressed packing where
there are zero bits of padding. It only insures that there will be no full
bytes of padding in the structure or union.
NOTE
The above alignment modes are only available on HP-UX systems.
The HP_ALIGN pragma affects struct and union definitions as well as typedef declarations.
It causes data objects that are later declared using these types to have the size and
alignment as specified by the pragma.
The alignment pragma in effect at the time of data type declaration has significance. The
alignment pragma in effect at the time of data type declaration has precedence over the
alignment pragma in effect when space for a data object of the previously declared type is
allocated.