C/C++ Programmer's Guide (G06.25+)

Mixed-Language Programming for TNS/R and
TNS/E Native Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
8-23
Considerations When Interfacing to pTAL
C Module
/* C function that accepts pTAL routine as parameter */
void C_FUNC (short (*F) (short n))
{
short j;
j = (*F)(2);
/* lots of code */
}
pTAL Module
PROC c_func (x) LANGUAGE C; !EXTERNAL procedure declaration
! for C routine to be called
INT PROC 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;
C Routines as Parameters to pTAL
You can call pTAL routines and pass C routines as parameters. You can call a pTAL
entry-point identifier as if it were the routine identifier. C routines cannot be nested.
When a called pTAL routine in turn calls a C routine received as a parameter, the pTAL
routine assumes that all required parameters of the C routine are value parameters.
The pTAL compiler has no way of checking the number, type, or passing method
expected by the C routine. If the C routine requires a reference parameter, the pTAL
routine must explicitly pass the address by using the $XADR standard function for a
parameter.
In the following 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