TAL Programmer's Guide

TAL and C Guidelines
Mixed-Language Programming
17–16 096254 Tandem Computers Incorporated
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 C Data With TAL Using Pointers
To share C global data with TAL modules, follow these steps:
1. In the 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 “Parameters and Variables” later in this section.)
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.