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

Table Of Contents
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
7-25
Variables and Parameters
In this example, a large-memory-model TNS C module contains C_FUNC, which
expects a TAL procedure as a parameter. The TAL module contains:
An EXTERNAL procedure declaration for C_FUNC
TAL_PARAM_PROC, a routine to be passed as a parameter to C_FUNC
TAL_CALLER, a routine that calls C_FUNC and passes TAL_PARAM_PROC as a
parameter
C Module
/* C function that accepts TAL routine as a parameter */
void C_FUNC (short (*F) (short n))
{
short j;
j = (*F)(2);
/* lots of code */
}
TAL Module
PROC c_func (x) LANGUAGE C; !EXTERNAL procedure declaration
! for C routine to be called
INT PROC(32) x; !Parameter declaration
EXTERNAL;
INT PROC tal_param_proc (f); !Procedure to be passed as a
INT f; ! parameter to C_FUNC
BEGIN
RETURN f;
END;
PROC tal_caller; !Procedure that calls C_FUNC
BEGIN ! and passes TAL_PARAM_PROC
!Lots of code
CALL c_func (tal_param_proc);
!Lots of code
END;
PROC m MAIN;
BEGIN
CALL tal_caller;
END;
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: