HP Pascal/iX Programmer's Guide (31502-90023)

2-: 9
SUBPROGRAM Advantages.
Using SUBPROGRAM results in smaller object files and less link time. You
also get faster access to the first 8K bytes of globals. The SUBPROGRAM
option can also be specified with a list of routines to compile as few as
one procedure, if RLFILE is used.
SUBPROGRAM Limitations.
The variables must be in the exact same order and must be declared with
the same types. Otherwise, at run time the global variables used in one
compilation unit may not match the actual memory that matches the global
variables in a different compilation unit.
To avoid this problem, place all global variable, type, and constant
declarations in a file and include ($INCLUDE$) those files in all
compilation units. If you don't ensure that the variable, type, and
constant declarations match in all compilation units, your execution
results will be incorrect, but no error will occur at compile time or at
link time.
Using GLOBAL/EXTERNAL
The
GLOBAL
and
EXTERNAL
compiler options turn Pascal programs into global
and external compilation units. The compiler options must precede the
reserved word
program
.
The GLOBAL compiler option:
* Generates symbolic definitions for the global variables in the
compilation units.
* Generates code for the outer block and any procedures.
The EXTERNAL compiler option:
* Generates symbolic references for the global variables in the
compilation unit.
* Prevents the compiler from generating storage for global
variables.
* Does not generate code for the outer block and prevents the
compiler from generating an outer block. If there are statements
in an outer block, they are ignored.
When to Use GLOBAL/EXTERNAL.
Use GLOBAL/EXTERNAL when sharing global information with another
language, or when the number of global variables are too large to
recompile each time.
GLOBAL/EXTERNAL is also useful when global variables will change often.
GLOBAL/EXTERNAL Advantages.
The following are some advantages of using GLOBAL/EXTERNAL:
* When you use GLOBAL/EXTERNAL for separate compilation, the global
variables do not need to be listed in the same order.
* Since the variables are matched by name, only as many globals as
used need to be declared when using EXTERNAL.
* The storage for globals does not take up space in the program
file.