HP Pascal/iX Programmer's Guide (31502-90023)
2-: 8
There are four methods used for separate compilation. They are performed
by using modules and by using the compiler options SUBPROGRAM, GLOBAL,
and EXTERNAL.
Using modules is the preferred method for separate compilation from a
structured programming point of view. However, using modules does have
certain limitations, as does using SUBPROGRAM, GLOBAL, and EXTERNAL. You
must decide which method works in the way you prefer for your specific
situation.
The remainder of this section addresses separate compilation using
modules and each compiler option. The uses, advantages, and
disadvantages of each method are discussed to help you determine which
one to use.
For detailed information on SUBPROGRAM, GLOBAL, and EXTERNAL, refer to
the
HP Pascal/iX Reference Manual
or the
HP Pascal/HP-UX Reference
Manual
, depending on your implementation. For more information on
modules, see "Using Modules" in this chapter.
Using Modules
Once a
module
is created, the
import
statement makes that module
available to any other program or module. The importing compilation unit
receives the constant, type, variable, procedure, and function
declarations that are exported by the imported module.
When to Use Modules.
Use modules for separate compilation when you have an extremely large
program and when you would like easy accessibility to libraries.
Advantages of Using Modules.
Some advantages to separate compilation with modules are:
* Many modules can exist within an executable program, but with only
one main program.
* When a module changes, you only need to recompile units that refer
to the module.
* You can import types and variables from a module without
distributing the source. For example, you can extract information
from an object file, archive library, or MLIBRARY.
* The types and the object code are in sync. There's no possibility
of a mismatch.
* The constant, type, variable, procedure, and function declarations
that are not exported are hidden.
Using SUBPROGRAM
The
SUBPROGRAM
compiler option turns a Pascal program into a subprogram
compilation unit.
For separate compilation, SUBPROGRAM must be included in all compilation
units, except the compilation unit containing the outer block. No code
is generated for the outer block if used.
When to Use SUBPROGRAM.
SUBPROGRAM is recommended for use in compilation units where the global
variables won't change much.