Compiling with units – HP SunSoft Pascal 4.0 User Manual

Page 93

Advertising
background image

Program Construction and Management

69

4

The body of the procedure

say_hello

is not defined in this program unit,

but the program unit does contain a declaration of the interface to the
procedure. The keyword

extern

declares that

say_hello

is declared in a

module unit.

1

Module unit

—This unit can begin with an optional module header,

followed by a set of compilable declarations and definitions. Modules that
call externally defined routines must have declarations for those routines.

Here is an example:

Every program must have one and only one program unit; a program can have
any number of module units. Any unit can call procedures declared in any
other unit; each unit must have

external

declarations for every procedure it

uses that is not defined in that unit.

A module unit can also be used as a library, that is, as a collection of useful
routines that is shared among a number of programs.

Compiling with Units

Consider the units given in the previous section, “Using Program Units and
Module Units.” You can compile and link these units on a single line by
executing the following command, which then produces the executable,

a.out

.

hostname% pc program_unit.p module_unit.p

1. A statement that shows the interface of a routine is called a declaration, because it declares the name and

parameters of the routine. The set of statements that shows the entire routine, including the body, is called
the definition of the routine. There can be only one definition for a given routine, but every routine must be
declared in every module or program unit that uses it.

module module_unit;

procedure say_hello;

begin

writeln ('Hello, world.')

end;

Advertising