Language Implementation
7-35
7
#pragma pack
#pragma pack
n
When used without an alignment pragma or option, this pragma has the
same effect for both the gcc960 driver and the ic960 driver: it restricts the
maximum alignment value that is honored for structure members to
n
bytes. A value of 0 tells the compiler to revert to the maximum field
alignment in use before the last
#pragma pack. Before the first #pragma
pack
is encountered,
n
=16.
NOTE. The ic960 driver’s pragma align and the gcc960 and ic960
drivers’
pragma i960_align override pragma pack. The interaction of
pragma pack and the gcc960 driver’s pragma align is described
below.
Using #pragma pack with gcc960’s #pragma align
When a member alignment requirement would exceed
n
,
n
is used instead
— both for assigning the member's offset within its structure, and for
determining the member's contribution to the structure's formal alignment
requirement. It does not, however, restrict the overall formal alignment
calculation for structures described for gcc960’s
#pragma align. To
limit a structure's formal alignment requirement (presumably to limit extra
padding at the end) you must use gcc960’s
#pragma align in addition to
#pragma pack.
For example:
#pragma pack 2
struct s{
char a;
int b;
};