SLAU132V October 2004 – February 2020
The pack pragma can be used to control the alignment of fields within a class, struct, or union type. The syntax of the pragma in C/C++ can be any of the following.
#pragma pack (n) |
The above form of the pack pragma affects all class, struct, or union type declarations that follow this pragma in a file. It forces the maximum alignment of each field to be the value specified by n. Valid values for n are 1, 2, 4, 8, and 16 bytes.
#pragma pack ( push, n) |
#pragma pack ( pop ) |
The above form of the pack pragma affects only class, struct, and union type declarations between push and pop directives. (A pop directive with no prior push results in a warning diagnostic from the compiler.) The maximum alignment of all fields declared is n. Valid values for n are 1, 2, 4, 8, and 16 bytes.
#pragma pack ( show ) |
The above form of the pack pragma sends a warning diagnostic to stderr to record the current state of the pack pragma stack. You can use this form while debugging.
For more about packed fields, see Section 5.17.4.