Next:Weak Pragmas, Previous:Symbol-Renaming Pragmas, Up:Pragmas Accepted by GCC [Contents][Index]
For compatibility with Microsoft Windows compilers, GCC supports a setof#pragma pack directives that change the maximum alignment ofmembers of structures (other than zero-width bit-fields), unions, andclasses subsequently defined. Then value below specifies thenew alignment in bytes and may have the value 1, 2, 4, 8, and 16. Avalue of 0 is also permitted and indicates the default alignment (as ifno#pragma pack were in effect) should be used.
#pragma pack(n)Sets the new alignment according ton.
#pragma pack()Sets the alignment to the one that was ineffect when compilation started (see also command-line option-fpack-struct[=n]. SeeOptions for Code Generation Conventions).
#pragma pack(push[,n])Pushes the current alignmentsetting on an internal stack and then optionally sets the new alignment.
#pragma pack(pop)Restores the alignment setting to the onesaved at the top of the internal stack (and removes that stack entry).Note that#pragma pack([n]) does not influence this internalstack; thus it is possible to have#pragma pack(push) followed bymultiple#pragma pack(n) instances, with the original staterestored by a single#pragma pack(pop).
You can also use thepacked type attribute (seeCommon Type Attributes) to pack a structure. However, thepackedattribute interferes with#pragma pack, and attempting to usethem together may cause spurious warnings or unexpected behavior.
Some targets, e.g. x86 and PowerPC, support the#pragma ms_structdirective, which causes subsequent structure and union declarations tobe laid out in the same way as__attribute__ ((ms_struct)); seex86 Variable Attributes.
#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 directivewhich lays out subsequent structure and union declarations inin the same way as the documented__attribute__ ((scalar_storage_order)); seeCommon Type Attributes.
#pragma scalar_storage_order big-endian#pragma scalar_storage_order little-endianSet the storage order of scalar fields to big- or little-endian,respectively.
#pragma scalar_storage_order defaultGoes back to the endiannessthat was in effect when compilation started (see also command-line option-fsso-struct=endianness seeOptions Controlling C Dialect).
Next:Weak Pragmas, Previous:Symbol-Renaming Pragmas, Up:Pragmas Accepted by GCC [Contents][Index]