Program Construction and Management
71
4
In a real program,
header.h
would probably contain many declarations and
would be included in several modules. Aside from routine declarations,
header files often contain constant, type, and variable declarations.
Sharing Variables Between Units
Variables that are global across a unit (that is, not declared locally in a routine)
can be
public
or
private
. A
public
variable can be shared by any unit that
is linked to the unit that declares the variable. A
private
variable cannot be
shared.
You can use the
public
and
private
reserved words to declare that a
var
section declares
public
or
private
variables. For example:
When you do not use
public
or
private
, variables are
public
by default.
However, when you compile with the
-xl
option, variables are
private
by
default.
To share a
public
variable, simply declare it in each unit where you want to
share it. As long as the variable is
public
, each reference to that variable
accesses the same data.
program program_unit3 (output);
public var
x : integer;
private var
y : integer;
Summary of Contents for SunSoft Pascal 4.0
Page 14: ...xiv Pascal 4 0 User s Guide ...
Page 16: ...xvi Pascal 4 0 User s Guide ...
Page 30: ...6 Pascal 4 0 User s Guide 1 ...
Page 160: ...136 Pascal 4 0 User s Guide 6 ...
Page 268: ...244 Pascal 4 0 User s Guide 11 ...
Page 320: ...296 Pascal 4 0 User s Guide B ...
Page 331: ...Index 307 ...
Page 333: ......