Download Free Pascal Language Reference Guide
Transcript
Chapter 13 Programs, units, blocks A Pascal program can consist of modules called units. A unit can be used to group pieces of code together, or to give someone code without giving the sources. Both programs and units consist of code blocks, which are mixtures of statements, procedures, and variable or type declarations. 13.1 Programs A Pascal program consists of the program header, followed possibly by a ’uses’ clause, and a block. Programs - program program header ; block . - uses clause - program header program identifier - ( - program parameters - uses clause uses identifier list identifier , program parameters ) - ; - 6 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 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. 152