For compatibility with Microsoft Windows compilers, GCC supports a set of
#pragma directives that change the maximum alignment of members of structures (other than zero-width bit-fields), unions, and classes subsequently defined. The n value below always is required to be a small power of two and specifies the new alignment in bytes.
#pragma pack(n)simply sets the new alignment.
#pragma pack()sets the alignment to the one that was in effect when compilation started (see also command-line option -fpack-struct[=n] see Code Gen Options).
#pragma pack(push[,n])pushes the current alignment setting on an internal stack and then optionally sets the new alignment.
#pragma pack(pop)restores the alignment setting to the one saved at the top of the internal stack (and removes that stack entry). Note that
#pragma pack([n])does not influence this internal stack; thus it is possible to have
#pragma pack(push)followed by multiple
#pragma pack(n)instances and finalized by a single
Some targets, e.g. x86 and PowerPC, support the
#pragma ms_struct directive which lays out structures and unions subsequently defined as the documented
#pragma ms_struct onturns on the Microsoft layout.
#pragma ms_struct offturns off the Microsoft layout.
#pragma ms_struct resetgoes back to the default layout.
Most targets also support the
#pragma scalar_storage_order directive which lays out structures and unions subsequently defined as the documented
#pragma scalar_storage_order big-endiansets the storage order of the scalar fields to big-endian.
#pragma scalar_storage_order little-endiansets the storage order of the scalar fields to little-endian.
#pragma scalar_storage_order defaultgoes back to the endianness that was in effect when compilation started (see also command-line option -fsso-struct=endianness see C Dialect Options).
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.