1.2.61 $PACKENUM or $Z : Minimum enumeration type size

This directive tells the compiler the minimum number of bytes it should use when storing enumerated types. It is of the following form:

{$PACKENUM xxx}
{$MINENUMSIZE xxx}

Where the form with $MINENUMSIZE is for Delphi compatibility. xxx can be one of 1,2 or 4, or NORMAL or DEFAULT (or 0).

The default enumeration size depends on the compiler mode:

As an alternative form one can use {$Z1}, {$Z2}{$Z4}. The {$Z} form takes a +/- argument, where + is equivalent to {$Z4} and - is equivalent to {$Z1}.

So the following code

{$PACKENUM 1}
Type
  Days = (monday, tuesday, wednesday, thursday, friday,
          saturday, sunday);

will use 1 byte to store a variable of type Days, whereas it normally would use 4 bytes. The above code is equivalent to

{$Z1}
Type
  Days = (monday, tuesday, wednesday, thursday, friday,
          saturday, sunday);

or equivalent to

{$Z-}
Type
  Days = (monday, tuesday, wednesday, thursday, friday,
          saturday, sunday);

It is important to note that the number of elements is determined by the highest value of the enumeration. If the enumeration has assigned values, then the ”number of elements” is actually the highest value in the enumeration+1.

program Project1;
{$PACKENUM 2}
type
  TEnum = (a, b, c = $FFFF + 1);
begin
  writeln(sizeof(TEnum)); // 4
end.

will print 4 because the number of elements is $FFFF+2