/Zp (Pack Structure Members)

Option

/Zp[[{1|2|4}]]

When storage is allocated for structures, structure members are ordinarily stored as follows:

Items of type char or unsigned char, or arrays containing items of these types, are byte aligned.

Structures are word aligned; structures of odd size are padded to an even number of bytes.

All other types of structure members are word aligned.

To conserve space or to conform to existing data structures, you may want to store structures more or less compactly. The /Zp option and the pack pragma control how structure data are packed into memory.

Use the /Zp option to specify the same packing for all structures in a module. When you give the /Zpn option, where n is 1, 2, or 4, each structure member after the first is stored on n-byte boundaries depending on the option you choose. If you use the /Zp option without an argument, structure members are packed on one-byte boundaries. No space is allowed between /Zp and its argument.

On some processors, the /Zp option may result in slower program execution because of the time required to unpack structure members when they are accessed. For example, on an 8086 processor, this option can reduce efficiency if members with int or long type are packed in such a way that they begin on odd-byte boundaries.

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

Table 13.10 shows the interaction of the /Zp option with the pack pragma.

Table 13.10 Using the pack Pragma


Syntax
Compiled with /Zp Option?
Action

#pragma pack() Yes Reverts to packing specified on the command line for structures that follow
#pragma pack() No Reverts to default packing for structures that follow
#pragma pack(n) Yes or no Packs the following structures to the given byte boundary until changed or disabled

Example

CL /Zp PROG.C

This command causes all structures in the program PROG.C to be stored without extra space for alignment of members on int boundaries.