[next] [tail] [up]

### 16.1 Programs

A Pascal program consists of the program header, followed possibly by a ’uses’ clause, and a block.

_________________________________________________________________________________________________________
Programs
___________________________________________________________________

The program header is provided for backwards compatibility, and is ignored by the compiler.

The uses clause serves to identify all units that are needed by the program. All identifiers which are declared in the interface section of the units in the uses clause are added to the known identifiers of the program. The system unit doesn’t have to be in this list, since it is always loaded by the compiler.

The order in which the units appear is significant, it determines in which order they are initialized. Units are initialized in the same order as they appear in the uses clause. Identifiers are searched in the opposite order, i.e. when the compiler searches for an identifier, then it looks first in the last unit in the uses clause, then the last but one, and so on. This is important in case two units declare different types with the same identifier.

The compiler will look for compiled versions or source versions of all units in the uses clause in the unit search path. If the unit filename was explicitly mentioned using the in keyword, the source is taken from the filename specified:

program programb;
uses unita in ’..\unita.pp’;

unita is searched in the parent directory of the programb source file.

When the compiler looks for unit files, it adds the extension .ppu to the name of the unit. On linux and in operating systems where filenames are case sensitive when looking for a unit, the following mechanism is used:

1. The unit is first looked for in the original case.
2. The unit is looked for in all-lowercase letters.
3. The unit is looked for in all-uppercase letters.

Additionally, If a unit name is longer than 8 characters, the compiler will first look for a unit name with this length, and then it will truncate the name to 8 characters and look for it again. For compatibility reasons, this is also true on platforms that support long file names.

Note that the above search is performed in each directory in the search path.

The program block contains the statements that will be executed when the program is started. Note that these statements need not necessarily be the first statements that are executed: the initialization code of the units may also contain statements that are executed prior to the program code.

The structure of a program block is discussed below.

[next] [front] [up]