next up previous contents index
Next: Constants Up: Data types Previous: Set types

Enumeration types

Enumeration types are supported in Free Pascal. On top of the Turbo Pascal implementation, Free Pascal allows the following C-style extension of the enumeration type.

Type
  EnumType = (one, two, three, forty := 40);
As a result, the ordinal number of forty is 40, and not 4, as it would be when the '= 40' wasn't present.

When specifying such an enumeration type, it is important to keep in mind that you should keep initialized set elements in ascending order. The following will produce a compiler error:

Type
  EnumType = (one, two, three, forty := 40, thirty:=30);
It is necessary to keep forty and Thirty in the correct order.

Remarks :

  1. You cannot use the Pred and Succ functions on this kind of enumeration types. If you try to do that, you'll get a compiler error.
  2. Enumeration types are by default stored in 4 bytes. You can change this behaviour with the {$PACKENUM } compiler directive, which tells the compiler the minimal number of bytes to be used for enumeration types. For instance
    Type 
      LargeEnum = ( BigOne, BigTwo, BigThree );
    {$PACKENUM 1}
      SmallEnum = ( one, two, three );
    
    Var S : SmallEnum;
        L : LargeEnum;
    
    begin
      Writeln ('Small enum : ',Sizeof(S));
      Writeln ('Large enum : ',SizeOf(L));
    end.
    will, when run, print the following:
    Small enum : 1
    Large enum : 4
More information can be found in the Programmer's guide in the compiler directives section.

Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998