5

Compiling without the -xlOption

There are three ways of sharing variables and routines across units when you compile your program without the –xloption.

Sharing Public Variables

If you declare a variable in two or more separate units and the variable is public in both places, that variable is shared between units. Variables are public by default, unless you compile with the -xloption, in which case variables are private by default. In this example, the variable global is public by default, and thus shared between the program and the module.

The program unit,

shrvar_prog.p

The module unit, shrvar_mod.p. The assignment of a new value to global and max_array in the procedure proc in shrvar_prog.p is repeated in shrvar_mod.p.

program shrvar_prog;

var

global: integer;

procedure proc; external;

begin { program body } global := 1;

writeln('From MAIN, before PROC: ', global); proc;

writeln('From MAIN, after PROC: ', global) end. { shrvar_prog }

module shrvar_mod;

var

global: integer;

procedure proc;

begin

writeln('From PROC: ',global); global := global + 1

end; { proc }

Separate Compilation

77