PACK Directive

General Compiler Directive: Specifies the memory starting addresses of derived-type items (and record structure items).

Syntax

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

c
Is one of the following: C (or c), !, or *. (See Syntax Rules for General Directives.)

Rules and Behavior

Items of derived types, unions, and 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 /alignment or /vms 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.

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

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: Derived Type, STRUCTURE...END STRUCTURE, UNION...END UNION, General Compiler Directives

Example

 ! 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: