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 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 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 results 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 to begin do, 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.