EXTERNAL and GLOBAL EXTERNAL [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation
HP Business BASIC/XL Reference Manual
EXTERNAL and GLOBAL EXTERNAL
The EXTERNAL or GLOBAL EXTERNAL statement defines a non-intrinsic
procedure or function in an executable library so that the procedure can
be called from within the HP Business BASIC/XL program. The purpose of
the statement is to specify the name of the procedure or function that is
called from within the HP Business BASIC/XL program. If the name in the
executable library is different from that to be used within HP Business
BASIC/XL, the name of the entry point in the executable library can be
specified in the alias clause. The formal parameter list for the
EXTERNAL statement must correspond to the formal parameter list in the
procedure header of the external routine. Parameters are passed by
reference unless the formal parameter is preceded by the keyword VALUE.
Since the language used to write the external procedure or function
determines the size and format anticipated for the actual parameters, the
language that the external procedure or function is written in must be
included in the external's definition. If the external returns a value,
(it is a function) then the type of the value returned must be specified
if it is not the default numeric type for the main program, subprogram,
or function that the definition occurs in.
Syntax
{EXTERNAL}
GLOBAL {EXT } [lang] return_type identifier [ALIAS quoted_& str_lit]
[[ [{,} ] ]]
[[[ptype] parameter [{;} [ptype] parameter] ...]]
Parameters
GLOBAL Allowed only if the statement is in the main block of
the program. If GLOBAL appears, the statement is a
GLOBAL EXTERNAL statement; if GLOBAL is omitted, the
statement is an EXTERNAL statement.
A GLOBAL EXTERNAL definition can appear only in the main
block of the program and allows the external to be
called from either the main block or any procedure or
function within that program. An EXTERNAL statement can
appear in the main block or any procedure or function
and allows the declared external to be called locally.
Any local EXTERNAL declaration statement takes
precedence over that of a GLOBAL EXTERNAL declaration
statement, but only while the main block or procedure
that contains the local EXTERNAL definition is
executing.
lang One of the following terms for the language that the
external procedure or function is written in:
BASIC HP Business BASIC/XL (default if
not specified)
PASCAL Pascal/XL
PASCAL EXTENSIBLE A PASCAL/XL routine declared
using the EXTENSIBLE option. It
is followed here by the numeric
literal, extensible_count.
extensible_count is the number of
required parameters for the call
to the external routine. The
required parameters must be
supplied for each call from the
HP Business BASIC/XL calling
routine. Additional non-required
formal parameters can be supplied
in the actual parameter list
following the required
parameters. Note that a call to
an EXTENSIBLE routine will pass
an additional "hidden" parameter
to specify the number of
parameters actually passed.
Refer to the HP PASCAL Reference
Manual for additional
information.
HPC HP C/XL
return_type Type of the value returned by the function. Can be any
HP Business BASIC/XL type or the type BYTE (see "Calling
External Subunits" in chapter 3).
identifier The name used within the HP Business BASIC/XL program to
call the function or procedure. If calling a function
directly without using the FNCALL keyword, this name
must follow the syntax of an HP Business BASIC/XL
function name; that is, the prefix 'FN' must precede the
name. This name is downshifted before searching the
executable library for the entry point.
quoted_str_lit The name of the procedure or function in the executable
library. This name is referred to as the alias name.
The string provided is the case-sensitive name of the
external routine in the executable library.
ptype Parameter type. Applies to all parameters between this
ptype specification and the next ptype or string
parameter (as in the DIM statement). The ptype can be
any HP Business BASIC/XL type or the type BYTE (see
"Calling External Subunits" in chapter 3). Each formal
parameter specified to be a BYTE String$ must be
preceded by the keyword BYTE.
parameter One of the following:
[VALUE] If lang is BASIC, VALUE is ignored. If
identifier lang is PASCAL or HPC, VALUE indicates
that the parameter immediately
following it is to be passed by value
(rather than by reference).
#fnum where fnum is a file number as
described in chapter 6.
array_name Gives one asterisk per dimension or
([*[,*]...]) does not have asterisks. No asterisks
indicates an undefined number of
dimensions. Either format is legal,
but the format without asterisks is not
compilable. The maximum length of each
element is the same as declared for the
actual parameter by the calling program
unit.
Examples
100 GLOBAL EXTERNAL Calculate
110 GLOBAL EXTERNAL Add(INTEGER X,Y)
115 GLOBAL EXTERNAL PASCAL String_op(BYTE Str1$,Str2$)
120 EXTERNAL BASIC Subtract ALIAS "sub"(INTEGER X,Y;REAL Z)
130 EXTERNAL PASCAL REAL FNDiv ALIAS "DIV"(INTEGER A,B)
140 EXTERNAL PASCAL INTEGER FNDiv2 ALIAS "divide"(INTEGER A,B)
150 EXTERNAL PASCAL Blob(INTEGER VALUE A, B)
For a call to String_op, both actual parameters are passed by reference.
The first actual parameter is passed as a packed array of character. The
second actual parameter is passed as a Pascal string.
For a call to Blob, the first actual parameter is an integer passed by
value, and the second actual parameter is an integer passed by reference.
The following example shows is a HP Business BASIC/XL program that calls
an external Pascal program. The Pascal program is called using the
PASCAL EXTENSIBLE keywords.
extrext2
10 EXTERNAL PASCAL EXTENSIBLE=2 Pascal_extensible_2(SHORT INTEGER P1,&
REAL VALUE P2, INTEGER P3, SHORT REAL VALUE P4)
15 ! Declare and initialize the variables to be used as actual parameters
20 SHORT INTEGER Sint1
30 REAL Real1
40 INTEGER Int1
50 SHORT REAL Sreal1
60 Sint1=1;Real1=2;Int1=3;Sreal1=4
70 CALL Pascal_extensible_2(Sint1,Real1) ! pass 2 parameters
80 CALL Pascal_extensible_2(Sint1,Real1,Int1) ! pass 3 parameters
90 CALL Pascal_extensible_2(Sint1,Real1,Int1,Sreal1) ! pass 4 parameters
MPE/iX 5.0 Documentation