Movatterモバイル変換


[0]ホーム

URL:


Next:, Previous:, Up:Pragmas Accepted by GCC   [Contents][Index]


6.5.11 Structure-Layout Pragmas

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 on

Turns on the Microsoft layout.

#pragma ms_struct off

Turns off the Microsoft layout.

#pragma ms_struct reset

Goes 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-endian

Set the storage order of scalar fields to big- or little-endian,respectively.

#pragma scalar_storage_order default

Goes 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]


[8]ページ先頭

©2009-2026 Movatter.jp