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

Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
7-15
Sharing Data
return 1;
}
/* Access the TAL arrays by using the pointers */
TAL Code
STRUCT rec (
*
);
BEGIN
INT x;
STRING tal_str_array[0:9];
END;
INT .EXT tal_int_array[0:4]; !TAL data to share with C
STRUCT .EXT tal_struct (rec); !TAL data to share with C
INT status := -1;
INT PROC init_c_ptrs (tal_intptr, tal_strptr) LANGUAGE C;
INT .EXT tal_intptr;
STRING .EXT tal_strptr;
EXTERNAL;
PROC tal_main MAIN;
BEGIN
status := init_c_ptrs
(tal_int_array, tal_struct.tal_str_array);
!Do lots of work
END;
Sharing TNS C Data With TAL Using Pointers
To share TNS C global data with TAL modules, follow these steps:
1. In the TNS C module, declare the data using TAL-compatible identifiers, data
types, and alignments. (Alignments depend on byte or word addressing and
variable layouts as described in Variables and Parameters on page 7-17.)
C arrays and structures are automatically indirect.
2. In the TAL module, declare pointers to the data, using C-compatible data types.
3. In the TAL module, declare a routine to which C can pass the addresses of the
shared data.
4. In the TAL routine, initialize the pointers with the addresses sent by C.
5. Use the pointers in the TAL module to access the C data.