Separate Compilation
77
5
Compiling without the
-xl
Option
There are three ways of sharing variables and routines across units when you
compile your program without the
–xl
option.
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
-xl
option, 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
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 }
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
.
module shrvar_mod;
var
global: integer;
procedure proc;
begin
writeln('From PROC: ',global);
global := 1
end; { proc }
Содержание SunSoft Pascal 4.0
Страница 14: ...xiv Pascal 4 0 User s Guide ...
Страница 16: ...xvi Pascal 4 0 User s Guide ...
Страница 30: ...6 Pascal 4 0 User s Guide 1 ...
Страница 160: ...136 Pascal 4 0 User s Guide 6 ...
Страница 268: ...244 Pascal 4 0 User s Guide 11 ...
Страница 320: ...296 Pascal 4 0 User s Guide B ...
Страница 331: ...Index 307 ...
Страница 333: ......