C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
pack
 Example                                   Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
  Pragma:   pack
 
  Syntax:   #pragma pack( [{1 | 2 | 4 }] )
 
  Summary:  Specifies packing alignment for structure types.
 
     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
     compiler option or the pack pragma controls how structure data is
     "packed" into memory.
 
     Use the /Zp option to specify the same packing for all structures
     in a module. When you give the /Zp[n] 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 1-byte
     boundaries.
 
     On some processors, the /Zp option can 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 to specify packing other than the packing
     specified on the command line for particular structures. 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.
 
                         Compiled with
     Syntax              /Zp Option?     Action
 
     #pragma pack()      Yes             Reverts to packing
                                         specified by the compiler
                                         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
                                    -♦-