Avoiding Pitfalls in Multi-Language Programming

Different languages have different
requirements for parameter type checking. The
linker PARMCHECK option can be used to relax the type checking done.
Shared globals
With MPE/iX 5.0, global data symbols can now
be visible from an executable library
(XL). This allows sharing data between a program file and XLs, but beware that
these
symbols could now conflict with definitions in the program or in other XLs.
Exception Handling
Pitfalls:
MPE only allows one active trap procedure per process for each type of trap.
In order for some language features to work
properly, the trap handler for that language must be
active.
Some languages require explicit initialization of the trap handler when a routine is called
from a
foreign outer block.
The first call to a Basic routine will automatically set Basic trap handling, overriding any previous
trap
settings.
Recommendations
:
If you are using trap handling features in multiple languages, save and restore the traps across each
call to a routine in the other language(s).
Details:
While Cobol code is executing, it expects the Cobol trap mechanism to be armed in order for certain
exceptions to be processed correctly. In an all-Cobol
environment, this is normally done only once, by
the main program. The same is true for Fortran and Pascal.
Suppose a Cobol main program calls a Pascal subprogram, but nothing is done to change the trap-
handling environment. If a run-time error occurs in the Pascal
subprogram, it is likely to be reported
incorrectly. For example, a Pascal file I/O error might be reported with the
message "No SIZE
ERROR phrase (COBERR 747)".
Likewise, a Cobol subprogram called from a non-
Cobol outer block is likely to report errors in
mysterious ways.
During a call to a Transact routine, arithmetic trapping is always enabled via calls to HPENBLTRAP,
XARITRAP and XLIBTRAP, and is reset to the prior state upon return.
To enable Pascal trap handling, call U_INIT_TRAPS prior to calling the first Pascal routine.
To enable Fortran trap handling, call FTN_INITRAP prior to calling the first Fortran routine (if
e.g. ON
statements are used in the Fortran routines).
To enable Cobol trap handling, call COBOLTRAP to arm the Cobol trap mechanism.
When a non-Basic language calls a Basic
routine, the traps for the calling language will be changed
to Basic trap handling mode. Basic sets up its trap handling with
calls to XCONTRAP, XARITRAP,
and XLIBTRAP. This is done during program initialization, after the SYSTEM or SYSTEMRUN
statements, or when the BRK function is called with a positive
argument. Program initialization occurs
when a Basic main
program is run, or on the first call to a Basic routine from a foreign outer block.
Page
8
of
14
Avoiding Pitfalls in Multi
-
7/18/2008
http://www.hp.com/cgi
-
bin/pf
-
new.cgi?IN=http://jazz.external.hp.com/papers/lang/pgm_pi
...