Using the, Option, Using – HP SunSoft Pascal 4.0 User Manual

Page 104: Declarations

Advertising
background image

80

Pascal 4.0 User’s Guide

5

Using the

-xl

Option

When you use the –

xl

option, variables and top-level procedures and

functions declared in the program unit default to

private

. Look at the

difference when you compile and execute

shrvar_prog.p

and

shrvar_mod.p

with –

xl

. See the source code in “Sharing Public Variables”

on page 77.

Without –

xl

, the variable

global

in

shrvar_mod.p

is treated as

public

;

here,

global

is treated as

private

. Thus, the assignment:

global := global + 1;

is not reflected in

shrvar_prog.p

; instead, each file uses its own private copy

of

global

.

The following sections describe five ways of sharing variables and routines
across units when you compile your program with –

xl

.

Using

public var

Declarations

The following examples uses the

public

attribute in the var declaration to

make

global public

when you compile your program with

–xl

.

The commands to compile and
execute

shrvar_prog.p

and

shrvar_mod.p

with the

–xl

option

hostname% pc -xl shrvar_prog.p shrvar_mod.p

shrvar_prog.p:

shrvar_mod.p:

Linking:

hostname% a.out

From MAIN, before PROC: 1

From PROC : 0

From MAIN, after PROC: 1

Advertising