15.1.15 PACK Directive

The PACK directive specifies the memory starting addresses of derived-type items. This directive takes the following form: [See Note]

cDEC$ PACK:[{1|2|4}]

c
Is one of the following: C (or c), !, or * (see Section 15.1.1).

Rules and Behavior

Items of derived types and record structures are aligned in memory on the smaller of two sizes: the size of the type of the item, or the current alignment setting. The current alignment setting can be 1, 2, 4, or 8 bytes. The default initial setting is 8 bytes (unless a compiler option specifies otherwise). By reducing the alignment setting, you can pack variables closer together in memory.

The PACK directive lets you control the packing of derived-type or record structure items inside your program by overriding the current memory alignment setting.

For example, if CDEC$ PACK:1 is specified, all variables begin at the next available byte, whether odd or even. Although this slightly increases access time, no memory space is wasted. If CDEC$ PACK:4 is specified, INTEGER(1), LOGICAL(1), and all character variables begin at the next available byte, whether odd or even. INTEGER(2) and LOGICAL(2) begin on the next even byte; all other variables begin on 4-byte boundaries.

If the PACK directive is specified without a number, packing reverts to the compiler option setting (if any), or the default setting of 8.

The directive can appear anywhere in a program before the derived-type definition or record structure definition. It cannot appear inside a derived-type or record structure definition.

Examples

Consider the following:

 ! Use 4-byte packing for this derived type
 ! Note PACK is used outside of the derived-type definition
 !DEC PACK:4
 TYPE pair
    INTEGER a, b
 END TYPE
 ! revert to default or compiler option
 !DEC PACK:

Note: The following form is also allowed: !MS$PACK:[{1|2|4}]

For More Information:


Previous Page Next Page Table of Contents