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

In a large-memory-model TNS C module, you can use the _lowmem storage class specifier to
allocate a C array or structure that can be represented by a 16-bit address if needed in a call to
a TAL routine or a system procedure.
Using pointers to share data is easier and safer than trying to match declarations in both languages.
Using pointers also eliminates problems associated with where the data is placed.
To share data by using pointers, first decide whether the TAL module or the TNS C module is to
declare the data:
If the TAL module is to declare the data, follow the guidelines in Sharing TAL Data With TNS
C Using Pointers.
If the TNS C module is to declare the data, follow the guidelines in Sharing TNS C Data With
TAL Using Pointers (page 108).
Sharing TAL Data With TNS C Using Pointers
To share TAL global data with TNS C modules, follow these steps:
1. In the TAL module, declare the data using C-compatible identifiers, data types, and alignments.
(Alignments depend on byte or word addressing and variable layouts as described in Variables
and Parameters (page 109).)
When you declare TAL arrays and structures, use indirect addressing.
2. In the TNS C module, declare pointers to the data, using TAL-compatible data types.
3. In the TNS C module, declare a routine to which TAL can pass the addresses of the shared
data.
4. In the C routine, initialize the pointers with the addresses sent by the TAL module.
5. Use the pointers in the TNS C module to access the TAL 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);
Interfacing to TAL 107