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

BEGIN
!Lots of code main ()
IF n = yes THEN ... ; {
!Lots of code answer = yes;
END; TAL_PROC (answer);
/* lots of code */
}
pTAL Routines as Parameters to C
You can call C routines and pass pTAL routines as parameters. You can pass any pTAL routine
except EXTENSIBLE or VARIABLE routines as parameters.
A passed pTAL routine can access the routine’s local variables and global pTAL variables. The
passed routine can contain subprocedures, but they cannot be passed as parameters.
In this example, a C module contains C_FUNC, which expects a pTAL procedure as a parameter.
The pTAL 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 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
138 Mixed-Language Programming for TNS/R and TNS/E Native Programs