Next: , Previous: Symbol-Renaming Pragmas, Up: Pragmas


5.53.7 Structure-Packing Pragmas

For compatibility with Win32, GCC supports a set of #pragma directives which change the maximum alignment of members of structures (other than zero-width bitfields), unions, and classes subsequently defined. The n value below always is required to be a small power of two and specifies the new maximum alignment in bytes.

  1. #pragma pack(n) pushes the current maximum alignment setting onto an internal stack and then sets the new maximum alignment. (APPLE ONLY)
  2. #pragma pack() acts like a #pragma pack(pop) directive. (APPLE ONLY)
  3. #pragma pack(push[,n]) pushes the current maximum alignment setting onto an internal stack and then optionally sets the new maximum alignment.
  4. #pragma pack(pop) restores the maximum alignment setting to the one saved at the top of the internal stack (and removes that stack entry).

Some targets, e.g. i386 and powerpc, support the ms_struct #pragma which lays out a structure as the documented __attribute__ ((ms_struct)).

  1. #pragma ms_struct on turns on the layout for structures declared.
  2. #pragma ms_struct off turns off the layout for structures declared.
  3. #pragma ms_struct reset goes back to the default layout.