/Zp (Struct Member Alignment)

Controls how the members of a structure are packed into memory and specifies the same packing for all structures in a module.

Syntax

/Zp[1|2|4|8|16]

Remarks

The /Zpn option tells the compiler where to store each structure member. The compiler stores members after the first one on a boundary that's the smaller of either the size of the member type, or an n-byte boundary.

The available packing values are described in the following table:

/Zp argument Effect
1 Packs structures on 1-byte boundaries. Same as /Zp.
2 Packs structures on 2-byte boundaries.
4 Packs structures on 4-byte boundaries.
8 Packs structures on 8-byte boundaries (default for x86, ARM, and ARM64).
16 Packs structures on 16-byte boundaries (default for x64).

Don't use this option unless you have specific alignment requirements.

Warning

C++ headers in the Windows SDK set and assume /Zp8 packing internally. Memory corruption may occur if the /Zp setting is changed inside the Windows SDK headers. The headers aren't affected by any /Zp option you set on the command line.

You can also use pack to control structure packing. For more information about alignment, see:

To set this compiler option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio.

  2. Select the Configuration Properties > C/C++ > Code Generation property page.

  3. Modify the Struct Member Alignment property.

To set this compiler option programmatically

See also

MSVC Compiler Options
MSVC Compiler Command-Line Syntax