next up previous contents index
Next: Enumeration types Up: Data types Previous: Records

Set types

Free Pascal supports the set types as in Turbo Pascal. The prototype of a set declaration is:

SetType = Set of TargetType;

Each of the elements of SetType must be of type TargetType. TargetType can be any ordinal type with a range between 0 and 255. A set can contain maximally 255 elements.

The following is a valid set declaration:

Type Days = (Mon, Tue, Wed, Thu, Fri, Sqt, Sun);

Var WeekDays : Set of days;
Given this set declaration, the follwing assignment is legal:
WeekDays := [ Mon, Tue, Wed, Thu, Fri];
The operators for manipulations of sets are listed in table (1.4).

  

Operation Operator
Union +
Difference -
Intersection *
Table 1.4: Set Manipulation operators

You can compare two sets with the <> and = operators, but not (yet) with the < and > operators.

As of compiler version 0.9.5, the compiler stores small sets (less than 32 elements) in a longint, if the type range allows it. This allows for faster processing and decreases program size. Otherwise, sets are stored in 32 bytes.



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