/Zp (Struct Member Alignment)

Switch View :
ScriptFree
Visual Studio 2010 - Visual C++
/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.

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

When you specify this option, each structure member after the first is stored on either the size of the member type or n-byte boundaries (where n is 1, 2, 4, 8, or 16), whichever is smaller.

The available values are described in the following table.

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).

16

Packs structures on 16-byte boundaries.

You should not use this option unless you have specific alignment requirements.

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 How to: Open Project Property Pages.

  2. Click the C/C++ folder.

  3. Click the Code Generation property page.

  4. Modify the Struct Member Alignment property.

To set this compiler option programmatically

See Also

Reference

Community Content

Ben_userdn
Issues around alignment
It is recommended that the default alignment be used whenever possible. Not doing so may lead to unexpected errors. For example, when building a 64-bit native Windows C++ application with /Zp1, the following problems manifest: wingdi.h causes the compiler to see the BITMAP structure is being 28 bytes in size while the GetObject function will fail if it is not 32 bytes in size. Also Windows API registry and CreateWindow calls will fail if the string arguments passed are in Unicode and not aligned on a 8-byte boundary.