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

!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 (page 109).)
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.
This example shows how to share C data with a TAL module. The TNS C module passes the
addresses of two C arrays to a TAL routine. The TAL routine assigns the array addresses to TAL
pointers.
C Code
#include <stdioh> nolist
short arr[5]; /* C data to share with TAL */
char charr[5]; /* C data to share with TAL */
_tal void INIT_TAL_PTRS ( short _far *, char _far * )
_tal _alias ("tal^name") void C_Name (void);
void example_func( int *x )
{
printf("x before TAL = %d\n", x[2] );
C_Name( );
printf("x after TAL = %d\n", x[2] );
}
main ()
{
INIT_TAL_PTRS ( &arr[0], &charr[0] ); /* initialize ptrs */
/* test pointer values */
arr[0] = 8;
example_func( arr );
arr[2] = 18;
charr[2] = 'B';
}
TAL Code
INT .EXT tal_int_ptr; !Pointer to C data
STRING .EXT tal_char_ptr; !Pointer to C data
PROC init_tal_ptrs (c_addr1, c_addr2); !Called from C
INT .EXT c_addr1;
STRING .EXT c_addr2;
BEGIN
@tal_int_ptr := @c_addr1;
@tal_char_ptr := @c_addr2;
END;
PROC tal^name;
BEGIN
tal_int_ptr[0] := 10;
tal_int_ptr[2] := 20;
tal_char_ptr[2] := "A";
END;
108 Mixed-Language Programming for TNS Programs