[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

#### 8.1.8.2 The Source Structure of UCSD/Borland Pascal Units

A generic GNU Pascal unit looks like the following:

    unit name;

    interface

    import part

    interface part

    implementation

    implementation part

    initialization part

    end.

The name of the unit should coincide with the name of the file with the extension stripped. (If not, you can tell GPC the file name with ``uses foo in 'bar.pas''`, see section 9.293 uses.)

The import part is either empty or contains a ``uses'` clause to import other units. It may also consist of an ISO-style ``import'` specification. Note that the implementation part is not preceeded by a second import part in GPC (see section 9.113 import).

The interface part consists of constant, type, and variable declarations, procedure and function headings which may be freely mixed.

The implementation part is like the declaration part of a program, but the headers of procedures and functions may be abbreviated: Parameter lists and function return values may be omitted for procedures and functions already declared in the interface part.

The initialization part may be missing, or it may be a ``begin'` followed by one or more statements, such that the unit has a statement part between this ``begin'` and the final ``end'`. Alternatively, a unit may have ISO-style module initializers and finalizers, see section 9.278 to begin do, section 9.279 to end do.

Note that GPC does not yet check whether all interface declarations are resolved in the same unit. The implementation of procedures and functions which are in fact not used may be omitted, and/or procedures and functions may be implemented somewhere else, even in a different language. However, relying on a GPC bug (that will eventually be fixed) is not a good idea, so this is not recommended. Instead, declare such routines as ``external'`.

A unit exports everything declared in the interface section. The exported interface has the name of the unit and is compatible with Extended Pascal module interfaces since GPC uses the same code to handle both.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Frank Heckenbach on May, 10 2002 using texi2html