C/C++ Programmer's Guide (G06.27+, H06.08+, J06.03+)

TNS C Routines as Parameters to TAL
You can call TAL routines and pass TNS C routines as parameters. You can call a TAL entry-point
identifier as if it were the routine identifier. TNS C routines cannot be nested.
When a called TAL routine in turn calls a TNS C routine received as a parameter, the TAL routine
assumes that all required parameters of the TNS C routine are value parameters. The TAL compiler
has no way of checking the number, type, or passing method expected by the TNS C routine. If
the TNS C routine requires a reference parameter, the TAL routine must explicitly pass the address
by using:
The @ operator for a small-memory-model parameter
The $XADR standard function for a large-memory-model parameter
In this example, a TNS C large-memory-model module contains TNS C routine C_PARAM_FUNC,
which is to be passed as a parameter. The TAL module contains:
An EXTERNAL procedure declaration for C_PARAM_FUNC
TAL_PROC, which expects C_PARAM_FUNC as a parameter
TAL_CALLER, which calls TAL_PROC and passes C_PARAM_FUNC as a parameter
TAL Module
INT i;
STRING .EXT s[0:9];
PROC c_param_func (i, s) !EXTERNAL procedure declaration
LANGUAGE C; ! for C routine expected as
INT i; ! a parameter
STRING .EXT s; !Extended indirection for large-
EXTERNAL; ! memory-model
PROC tal_proc (x); !TAL routine that expects
PROC(32) x; ! a large-memory-model C routine
BEGIN ! as a parameter
CALL x (i, $XADR (s));
END;
PROC tal_caller;
BEGIN
CALL tal_proc (c_param_func);
END;
PROC m main;
BEGIN
CALL tal_caller;
END;
C Module
void C_PARAM_FUNC (short i, char * s)
{ /* C routine to be passed as */
/* a parameter to TAL_PROC */
}
When you pass a large-memory-model TNS C routine as a parameter, the compiler passes a 32-bit
address that contains PEP and map information in the high-order word and a zero in the low-order
word. When you pass a small-memory-model TNS C routine as a parameter, the compiler passes
a 16-bit address that contains PEP and map information.
Extended Data Segments
In addition to the user data segment, you can store data in:
The automatic extended data segment
One or more explicit extended data segments
You should use only the automatic extended data segment if possible. You should not mix the two
approaches. If you must use explicit segments and the automatic segment, however, follow guidelines
4 and 11 in Explicit Extended Data Segments.
116 Mixed-Language Programming for TNS Programs