next up previous
Next: Simple types Up: DECLARATIONS Previous: DECLARATIONS

TYPE

A type declaration specifies to the compiler that a given identifier or name will designate a type of data that may be referred to in the program, i.e., an abstract set of data values.

There are types already defined by the GLIDER or Pascal system (REAL, INTEGER, BOOLEAN, CONT, POINTER etc.).

Each variable in a program must be declared indicating its type. With this information the compiler reserve to that variable enough memory space to hold its values, that must belong to the type. This information also could be used by the compiler to validate that only values belonging to the type are assigned at run time.

Type identifiers may be referred to in other type declarations in order to define new types. A trivial case is to define an 'alias' to an existing type, as in the following example: Decimal = REAL

The true usefulness of type declaration is not this mere 'alias' to predefined types, but when new structured types have to be defined.

New types may be defined for convenience of clarity and maintenance, otherwise type specifications for variables may be stated directly in variable declarations.

In the following example the new type Arr5 is declared:

    TYPE Arr5 = ARRAY[1..5] OF REAL;
With this new type the programmer can avoid to declare the variables A, B, z, X in this way:
    VAR  A, B: ARRAY[1..5] OF REAL;.......;
    ......................
    VAR  z: ARRAY[1..5] OF REAL; ... X: ARRAY[1..5] OF REAL;
Instead, the programmer only needs to write:
    VAR  A, B: Arr5;.......;
    VAR  z: Arr5;....; X: Arr5;...
Note the use of the = sign for new type declarations whereas the : sign is used for type specification in variable declarations.

New types declarations are mandatory in Pascal when the user needs to pass a structured variable in the parameter list of a function or procedure, as Pascal syntax only accepts type identifiers in parameter list declarations.

The reader may consult Pascal and TurboPascal bibliography for a complete description on types. Restrictions or changes in GLIDER to Pascal syntax and use will be stated when appropriate.

GLIDER includes the following predefined types and type constructors for new type declarations or variable type specifications:




next up previous
Next: Simple types Up: DECLARATIONS Previous: DECLARATIONS

domingo c
Mon Mar 20 11:09:25 PST 2000