Node:Type Declaration, Next:Variable Declaration, Previous:Constant Declaration, Up:Source Structures

#### Type Declaration

A type declaration looks like this:

    type
      type_identifier = type_definition;
      ...
      type_identifier = type_definition;

or, with preset content:

    type
      type_identifier = type_definition value constant_expression;
      ...
      type_identifier = type_definition value constant_expression;

A type declaration part begins with the reserved word `type`. It declares a type_identifier which is defined by type_definition. A type definition either can be an array, a record, a schema, a set, an object, a subrange, an enumerated type, a pointer to another type_identifier or simply another type_identifier which is to alias. If a schema type is to be declared, type_identifier is followed by a discriminant enclosed in parentheses:

    type_identifier (discriminant) = schema_type_definition;

If `value` is specified, followed by a constant satisfying the type definition, every variable of this type is initialized with constant_expression, unless it is initialized by `value` itself. The reserved word `value` can be replaced by `=`, however `value` is not allowed in ISO-Pascal and Borland Pascal, and the replacement by `=` is not allowed in Extended Pascal.

#### Type declaration example

    type
      { This side is the }     { That side is the }
      { type declaration }     { type definition  }

      Arrayfoo            = array [0 .. 9] of Integer;  { array definition }
      Recordfoo           = record                      { record definition }
                              Bar: Integer;
                            end;

           { schema def with discriminants ``x, y: Integer'' }
      SchemaFoo (x, y: Integer) = array [x .. y] of Integer;
      CharSetFoo          = set of Char;              { Def of a set }
      ObjectFoo           = object                    { Def of an object }
                              procedure DoAction;
                              constructor Init;
                              destructor Done;
                            end;
      SubrangeFoo         = -123..456;                { subrange def }

      EnumeratedFoo       = (Pope,John,the,Second);   { enum type def }
           { Def of a pointer to another type identifier }
      PInteger            = ^arrayfoo;
           { Def of an alias name for another type identifier }
      IdentityFoo         = Integer;
           { Def of an integer which was initialized by 123 }
      InitializedFoo      = Integer value 123;

#### See also

Type Definition, Data Types, Variable Declaration