Chapter Contents |
Previous |
Next |
Using the indep Option for Interlanguage Communication |
Initialization Considerations |
Using the longjmp Function in a Multilanguage Program |
When you have a multilanguage program compiled with
the
indep
option, you ordinarily cannot use
longjmp
to transfer control
from one routine to another if this would terminate a non-C routine. If you
attempt this, a user ABEND 1224 results. This restriction is imposed because
longjmp
cannot guarantee that bypassing the normal return from the non-C routine
will not cause random failures in non-C code.
If your application requires the use of
longjmp
in this fashion,
you can modify the L$UPREP routine to remove this restriction. However, if
you do so, be aware that this may cause unpredictable results later in execution,
depending on the implementation of function linkage in the other language.
Reentrancy |
Note that the version of L$UPREP provided by CICS stores
the CRAB address in the first word of the Transaction Work Area (TWA) so that
CICS application programs compiled when the
indep
option is specified will be
reentrant; this is a CICS requirement. A transaction which invokes a C program
compiled with the
indep
option must be defined with a TWA.
main Function Considerations |
Ordinarily, when you call C functions from another language,
there is no C
main
routine because the program is composed of a main routine in the
other language combined with C and other subroutines. Sometimes it is necessary
to have a C
main
function, usually because an existing C program is being modified
to be called from another language. This section describes the special considerations
in such a case.
When you link code compiled with
indep
with a C function
named
main
, the
main
function normally must also be compiled with
indep
. This means that
L$UPREP is called to create the C execution framework if it does not exist
and to save the CRAB address for later access by the L$UCENV macro. In this
special case, the C execution framework is terminated when
main
returns. Therefore,
you do not need to call L$UEXIT after a call to a
main
function.
When the compiler processes a function named
main
, the corresponding
external symbol is named @MAIN. When you call a
main
function compiled
with
indep
from another language, you must use this entry point name. Use
of the name MAIN (without @) passes control directly to the run-time library
on program entry, bypassing L$UPREP and L$UCENV for framework initialization.
This means that necessary information is not stored for use by later non-C
calls to C.
One difficulty that can arise when you call a
main
function from another language is that storage referenced by L$UCENV may not
always exist at the time that
main
is called. This situation can occur, for example,
if L$UCENV references a user word provided by another language and C code
is invoked before any code in the other language. In this case, if possible,
you should change the processing order so that required storage can be allocated
before
main
is called (by calling the other language before C).
If it is not possible to change the processing order,
an alternative technique can be used in which you compile the
main
function without
indep
.
Then, the C execution framework is created by L$CMAIN when the C
main
function is invoked.
The fact that storage may not be available does not matter because a
main
routine that is not compiled with the
indep
option does not invoke L$UPREP.
In addition, you must store the CRAB address yourself before any C function
compiled with
indep
is called so that it can be accessed by L$UCENV. To do this,
you need to write an assembler routine and invoke it after the other storage
is accessible (for example, after the other language's execution framework
has been created) and before any C functions compiled with
indep
are called.
Note:
The technique above is not directly applicable to SPE.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.