The EXTERNAL directive allows an HP Pascal compilation unit
to access an external routine (a routine in another compilation
unit). The source code of the external routine can be any one of
the following languages:
Syntax
[EXTERNAL [CCOBOLFORTRANFTN77SPLSPL VARIABLE]]
Parameters
- None
The source code of the external routine is HP Pascal
or Pascal/V.
- C
The source code of the external routine is C. See
Table 9-1 “Corresponding HP Pascal and HP C Types” for corresponding HP
Pascal and C types.
- COBOL
The source code of the external routine is COBOL
II. See Table 9-2 “Corresponding HP Pascal and Cobol II Types” for corresponding
HP Pascal and COBOL II types.
- FORTRAN
The source code of the external routine is FORTRAN
66/V. The compilation unit that makes the call must also contain
the compiler option HP3000_16 (see compiler options in the HP
Pascal/iX Reference Manual or the HP Pascal/HP-UX
Reference Manual). See Table 9-3 “Corresponding HP Pascal and FORTRAN 77
or FORTRAN 66/V Types ” for corresponding HP Pascal and FORTRAN
66/V types.
- FTN77
The source code of the external routine is FORTRAN
77. See Table 9-3 “Corresponding HP Pascal and FORTRAN 77
or FORTRAN 66/V Types ” for corresponding
HP Pascal and FORTRAN 77 types.
- SPL
The source code of the external routine is SPL,
without option variable parameters. The compilation unit that makes
the call must also contain the compiler option HP3000_16 (see compiler
options in the HP Pascal/iX Reference Manual
or the HP Pascal/HP-UX Reference Manual).
See Table 9-4 “Corresponding HP Pascal and SPL Types” for corresponding
HP Pascal and SPL types.
- SPL VARIABLE
The source code of the external routine is SPL,
with optional variable parameters. You must specify SPL VARIABLE
(rather than SPL)
if the external routine has option parameters, even if you do not
omit parameters when you call the routine. The compilation unit
that makes the call must also contain the compiler option HP3000_16
(see compiler options in the HP Pascal/iX Reference Manual
or the HP Pascal/HP-UX Reference Manual).
See Table 9-4 “Corresponding HP Pascal and SPL Types” for corresponding
HP Pascal and SPL types.
The programmer is responsible for matching the formal parameters
and result type of the routine containing the EXTERNAL directive
with the formal parameters and result type of the external routine.
The matching rules are:
Corresponding formal parameter lists
must have the same number of parameters in the same order.
Corresponding formal parameters must be of corresponding
types. (Correspondence depends upon the source language of the external
routine. See the parameter descriptions, below.)
Corresponding formal parameters can have different
names.
The INTRINSIC directive is more flexible about matching. See
Chapter 10 “Intrinsics ” for details.
The EXTERNAL directive replaces the block in a routine declaration
(see the HP Pascal/iX Reference Manual or
the HP Pascal/HP-UX Reference Manual for
details). The declaration containing the EXTERNAL directive can
be at any level, but the external routine itself must be at level
one in its own compilation unit.
Example 1
The Pascal program Pascal_Pascal
calls the external Pascal procedure psubproc.
This is the program:
$GLOBAL$ PROGRAM Pascal_Pascal(output); CONST looplimit = 10; TYPE loopbound = 1..looplimit; VAR loop : loopbound; global, dynamic, static : integer; PROCEDURE psubproc ( parm1 : integer; VAR parm2 : integer); EXTERNAL; BEGIN {pascal_pascal} dynamic := 0; FOR loop := 1 to looplimit DO BEGIN IF loop <= 5 THEN static := 10 ELSE static := 20; global := loop; psubproc(static,dynamic); write('Cycle = ', loop, 'Total = ', dynamic); END; write('Finish processing'); END. {pascal_pascal} |
This is the external Pascal procedure:
$EXTERNAL$ PROGRAM PASCALSUB; VAR global : integer; PROCEDURE psubproc ( adder : integer; VAR total : integer); VAR localconstant : integer; BEGIN {psubproc} IF (global MOD 2) = 0 THEN localconstant := adder * 2 ELSE localconstant := adder; total := total + localconstant; END; {psubproc} BEGIN END. |
You can use the EXTERNAL directive with procedure declarations
in the implement part of a module. In such a procedure declaration,
repeating the formal parameters is optional. If you do repeat them,
they must be identical to those in the export section.
Example 2
MODULE m; EXPORT PROCEDURE proc1 (VAR parm1 : integer; VAR parm2 : char); PROCEDURE proc2 (VAR parm1 : integer); IMPLEMENT PROCEDURE proc1; {formal parameters omitted} EXTERNAL; PROCEDURE proc2 (VAR parm1 : integer); {formal parameter repeated} EXTERNAL; END; |
Use the EXTERNAL directive in exported procedures to link
routines written in other languages into your program. You are responsible
for ensuring that the formal parameters of the exported procedure
correspond to those of the actual external procedure.
 |
 |  |
 |
 | NOTE: Do not confuse the EXTERNAL directive with the EXTERNAL
compiler option. Refer to the HP Pascal/iX Reference
Manual or the HP Pascal/HP-UX Reference Manual,
depending on your implementation, for information on the EXTERNAL
compiler option. |
 |
 |  |
 |