/Zp - Pack Structure Members

This option allows you to control the alignment of structure members in memory. Ordinarily, when storage is allocated for structures, their members are DWORD-aligned using the default value, /Zp8. The default value, /Zp8, provides maximum portability when using the Win32 API to develop applications for Microsoft Windows NT® or Windows CE.

/Zp[<{1|2|4|8|16}>]

The /Zp option and the pack pragma control how structure data are packed into memory. You can use this option to conserve space or to conform to existing data structures. The /Zp option specifies the same packing for all structures in a module.

When you select the /Zpn option, where n is 1, 2, 4, 8, or 16, each structure member after the first is stored on n-byte boundaries. If you use the /Zp option without an argument, structure members are packed on 1-byte boundaries. No space is allowed between /Zp and its argument.

If no n-byte boundary argument is specified for #pragma pack(), the packing behavior of the compiler varies with the use of the /Zp option. The following list shows the interaction of the /Zp option with the pack pragma if no n-byte argument is specified.

  • If #pragma pack() is compiled with the /Zp option, it uses the packing specified on the command line for structures that follow.
  • If #pragma pack() is NOT compiled with the /Zp option, it reverts to default packing for structures that follow.

Use the pack pragma in your source code to pack individual structures on boundaries different from the packing specified on the command line. Give the pack(n) pragma, where n is 1, 2, 4, 8, or 16, before structures that you want to pack differently. To reinstate the packing given on the command line, give the pack() pragma with no arguments.

If an n-byte argument specified for #pragma pack(n), then the compiler packs the structures that follow to the given byte boundary until the packing instruction is changed or disabled.

The /Zp option will result in slower program execution because of the time required to unpack structure members when they are accessed. For example, this option will reduce efficiency if you pack members with int or long types in such a way that they begin on odd-byte boundaries.

All supported compilers implement the /Zp option. The following examples show how to use the /Zp option to store all structures in PROG.c without using extra space for alignment of members on char boundaries.

  • ARM Compiler

    CLARM /Zp PROG.C
    
  • THUMB Compiler

    CLTHUMB /Zp PROG.C
    
  • SHx Compiler

    CLSH /Zp PROG.C
    
  • MIPS Compiler

    CLMIPS /Zp PROG.C
    

See Also

About Microprocessor Compilers | ARM Guide | Hitachi Guide | MIPS Guide

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.