C/C++ Programmer's Guide (G06.25+)
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
7-10
Calling TNS C Routines From TAL Modules
Calling TNS C Routines From TAL Modules
A TAL module must include an EXTERNAL procedure declaration for each TNS C
routine to be called. The following TAL code shows the EXTERNAL procedure
declaration for C_FUNC and a routine that calls C_FUNC. ARRAY is declared with
.EXT, because C_FUNC uses the large-memory model:
TAL Code C Code
INT status := 0; short C_FUNC(char *str)
STRING .EXT array[0:4]; {
*str = 'A';
INT PROC c_func (a) str[2] = 'C';
LANGUAGE C; return 1;
STRING .EXT a; }
EXTERNAL;
PROC example MAIN;
BEGIN
array[2] := "B";
status := c_func (array);
array[1] := "B";
END;
A C-series TNS C module called by a TAL module has limited access to the C run-time
library. If the TNS C module needs full access to the C run-time library, you can either:
•
Modify the program to run in the CRE as described in this section.
•
Specify a C MAIN routine that calls the original TAL main routine as follows.
In the TAL module, remove the MAIN keyword from the TAL main routine and
remove any calls to the INITIALIZER or ARMTRAP system procedure. The TAL
module must also meet the requirements of the C run-time environment.
TAL Code C Code
#include <stdioh> nolist
INT status := 0;
INT .EXT array[0:4]; _tal void TALMAIN ( void );
INT PROC cfunc (a) short CFUNC (short *num)
LANGUAGE C; {
INT .EXT a; printf("num B4=%d\n",*num);
EXTERNAL; num[0] = 10;
printf("num AF=%d\n",*num);
PROC talmain; return 1;
BEGIN }
array[2] := 2;
status := main () /* C MAIN routine */
cfunc (array); {
END; TALMAIN ();
}