Using extern option to share routines – HP SunSoft Pascal 4.0 User Manual

Page 102

Advertising
background image

78

Pascal 4.0 User’s Guide

5

Using

extern

Option to Share Routines

If a program or module calls a procedure not defined in that unit, you must
declare it with either the

extern

or

external

routine option. For instance, in

the previous example, the procedure

proc

is defined in

shrvar_mod.p

, but

used in

shrvar_prog.p

. Thus, it is declared as

external

in

shrvar_prog.p

. Also,

proc

must also be defined as public in

shrvar_mod.p

, which is the default.

Using

include

Files to Share Variables and Routines

The

include

file contains the declarations for the program. Placing all

program declarations in a single file makes your program more consistent and
easier to maintain.

To use this feature, place the number sign character (

#

) in the first position of a

line immediately followed by the word

include

, and then a file name

enclosed in angle brackets (

<

and

>

) or double quotation marks (

"

). The

different enclosures (

<>

and

""

) affect the search order for files. The syntax for

the

#include

directive is determined by

cpp

(1).

When the compiler encounters the

#include

in the input, it inserts the lines

from the included file into the input stream.

The commands to compile and
execute

shrvar_prog.p

and

shrvar_mod.p

hostname% pc shrvar_prog.p shrvar_mod.p

shrvar_prog.p:

shrvar_mod.p:

Linking:

hostname% a.out

From MAIN, before PROC: 1

From PROC : 1

From MAIN, after PROC : 2

Advertising