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-15
Sharing Data
This example shows how to share TAL data with a large-memory-model TNS C
module. The TAL module passes to a C routine the addresses of two TAL arrays. The
C routine assigns the array addresses to C pointers.
C Code
short *c_int_ptr; /* pointer to TAL data */
char *c_char_ptr; /* pointer to TAL data */
short INIT_C_PTRS (short *tal_intptr, char *tal_strptr)
{ /* called from TAL */
c_int_ptr = tal_intptr;
c_char_ptr = tal_strptr;
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.