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

routine requires a reference parameter, the pTAL routine must explicitly pass the address by using
the $XADR standard function for a parameter.
In this example, a C module contains C routine C_PARAM_FUNC, which is to be passed as a
parameter. The pTAL 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
pTAL 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); !pTAL routine that expects
PROC x; ! a C routine as a parameter
BEGIN
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 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.
Differences Between Native and TNS Mixed-Language Programs
The information in this section is for writing mixed-language native C or C++ programs. If you
need to write mixed-language native C or C++ programs that can run as both TNS and native
processes, you must also read Chapter 7: Mixed-Language Programming for TNS Programs.
To write mixed-language programs that run as both TNS and native processes, you must consider
at least these issues:
Data Models (page 139)
Memory Models (page 140)
_far Pointer Qualifier (page 140)
Extended Data Segments (page 140)
Data Models
The native C and C++ compilers support only one data model: the 32-bit or wide data model. The
size of int is always 32 bits. If you are writing C or C++ programs that you want to run as both
native and TNS processes, you must write code that expects the size of type int to be 32 bits. A
good program practice is to use short for all 16-bit integers and int for all 32-bit integers.
Differences Between Native and TNS Mixed-Language Programs 139