HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

ALIGN
#pragma align N
N is a number raised to the power of 2.
HP aC++ supports user-specified alignment for global data. The pragma takes effect on
next declaration. If the align pragma declaration is not in the global scope or if it is not
a data declaration, the compiler displays a warning message. If the specified alignment
is less than the original alignment of data, a warning message is displayed, and the
pragma is ignored. Note that for C code you must initialize the variables, otherwise the
compiler will generate a warning.
#pragma align 2
char c; // "c" is at least aligned on 2 byte boundary.
#pragma align 64
int i, a[10]; // "i" and array "a" are at least aligned 64 byte boundary.
// the size of "a" is still 10*sizeof(int)
PACK
#pragma PACK [n]|[push|pop]|[,<name>][,n]|show]
n can be 1, 2, 4, 8, or 16 bytes. If n is not specified, maximum alignment is set to the
default value.
This file-scoped pragma allows you to specify the maximum alignment of class fields.
The alignment of the whole class is then computed as usual, to the alignment of the most
aligned field in the class.
NOTE: The result of applying #pragma pack n to constructs other than class definitions
(including struct definitions) is undefined and not supported. For example:
#pragma pack 1
int global_var; // Undefined behavior: not a class definition
void foo() { // Also undefined
}
Example:
struct S1 {
char c1; // Offset 0, 3 bytes padding
int i; // Offset 4, no padding
char c2; // Offset 8, 3 bytes padding
}; // sizeof(S1)==12, alignment 4
#pragma pack 1
struct S2 {
char c1; // Offset 0, no padding
int i; // Offset 1, no padding
char c2; // Offset 5, no padding
Data Alignment Pragmas 119