Namespaces
Variants
Views
Actions

Template:cpp/preprocessor/pragma pack

From cppreference.com

This family of pragmas control the maximum alignment for subsequently defined class and union members.

#pragma pack(arg) (1)
#pragma pack() (2)
#pragma pack(push) (3)
#pragma pack(push, arg) (4)
#pragma pack(pop) (5)

where arg is a small power of two and specifies the new alignment in bytes.

1) Sets the current alignment to value arg.
2) Sets the current alignment to the default value (specified by a command-line option).
3) Pushes the value of the current alignment on an internal stack.
4) Pushes the value of the current alignment on the internal stack and then sets the current alignment to value arg.
5) Pops the top entry from the internal stack and then sets (restores) the current alignment to that value.

#pragma pack may decrease the alignment of a class, however, it cannot make a class overaligned.

See also specific details for GCC and MSVC.