gcc: Structure-Layout Pragmas

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