TAL Programmer's Guide

TAL and C Guidelines
Mixed-Language Programming
096254 Tandem Computers Incorporated 17–17
This example shows how to share C data with a TAL module. The 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 ( extptr short *, extptr char * )
_tal void C_Name = "tal^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;