Next: , Up: %typedef and %type

10.1 Declaring types

A type can be declared in a record descriptor by using the %typedef special field. The syntax is:

     %typedef: type_name type_description

Where type_name is the name of the new type, and type_description a description which varies depending of the kind of type. For example, this is how a type Age_t could be defined as numbers in the range 0..120:

     %typedef: Age_t range 0 120

Type names are identifiers having the following syntax:


Even though any identifier with that syntax could be used for types, it is a good idea to consistently follow some convention to help distinguishing type names from field names. For example, the _t suffix could be used for types.

A type can be declared to be a synonym of another type. The syntax is:

     %typedef: type_name other_type_name

Where type_name is declared to be a synonym of other_type_name. This is useful to avoid duplicated type descriptions. For example, consider the following example:

     %typedef: Id_t          int
     %typedef: Item_t        Id_t
     %typedef: Transaction_t Id_t

Both Item_t and Transaction_t are synonyms for the type Id_t. They are both numeric identifiers.

The order of the %typedef fields is not relevant. In particular, a type definition can reference other type that is defined below. The previous example could have been written as:

     %typedef: Item_t        Id_t
     %typedef: Transaction_t Id_t
     %typedef: Id_t          int

Integrity checks will complain if undefined types are referenced, and if there are loops (direct or indirect) in type declarations. For example, the following set of declarations contains a loop and are thus invalid:

     %typedef: A_t B_t
     %typedef: B_t C_t
     %typedef: C_t A_t

The scope of a type is the record descriptor where it is defined.