Rediger

Del via


/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 and ARM64EC).

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

Warning

The C/C++ headers in the Windows SDK assume the platform's default alignment is used. Don't change the setting from the default when you include the Windows SDK headers, either by using /Zp on the command line or by using #pragma pack. Otherwise, your application may cause memory corruption at runtime.

You can also use the pack pragma 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