$PACK directive

Purpose: $PACK specifies alignment for packing user defined TYPE structure and UNION members.

Similar to the compiler option -Zp[1,2,4,8,16], which provides module-level control, $PACK provides control at the data-declaration level. Alignment begins after $PACK at the first user defined TYPE structure or UNION declaration. Definitions are not effected by $PACK.


 Syntax 1:

 $PACK(Number) 

 Parameters:

  • Number is 1,2,4,8, or 16. This will align the members of a structure at 1(i.e., no packing) byte or at 2, 4, 8, or 16 bytes.

 Syntax 2:

 $PACK(push,Number) 

 Parameters:

  • push saves the current value of packing alignment. This value can be restored by using the $PACK(pop) directive.
  • Number can be 1, 2, 4, 8, or 16. The members of a user defined TYPE structure or UNION members will be aligned at 1(i.e., no packing) byte or at 2, 4, 8, or 16 bytes.

Here is a simple example that demonstrates usage of $PACK.


 $PACK(push,1)
 TYPE BMP_HEADER
  fIdentity    AS WORD
  fFileSize    AS LONG
  fReserved    AS LONG
  fOffset      AS LONG
  fHeaderSize  AS LONG
  fWidth       AS LONG
  fHeight      AS LONG
  fPlanes      AS WORD
  fBPP         AS WORD
  fCompression AS LONG
  fDataSize    AS LONG
  fHResolution AS LONG
  fVResolution AS LONG
  fColors      AS LONG
  fImpColors   AS LONG
 END TYPE
$PACK(pop)