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

return 1;
}
/* Access the pTAL arrays by using the pointers */
pTAL Code
STRUCT rec (*);
BEGIN
INT x;
STRING tal_str_array[0:9];
END;
INT tal_int_array[0:4]; !pTAL data to share with C
STRUCT tal_struct (rec); !pTAL 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 pTAL Using Pointers
To share C global data with pTAL modules, follow these steps:
1. In the C module, declare the data using pTAL-compatible identifiers, data types, and alignments.
(Alignments depend on byte or word addressing and variable layouts as described in
Parameters and Variables (page 134).)
C arrays and structures are automatically indirect.
2. In the pTAL module, declare pointers to the data, using C-compatible data types.
3. In the pTAL module, declare a routine to which C can pass the addresses of the shared data.
4. In the pTAL routine, initialize the pointers with the addresses sent by C.
5. Use the pointers in the pTAL module to access the C data.
This example shows how to share C data with an pTAL module. The C module passes the addresses
of two C arrays to a pTAL routine. The pTAL routine assigns the array addresses to pTAL pointers.
C Code
#include <stdioh> nolist
short arr[5]; /* C data to share with pTAL */
char charr[5]; /* C data to share with pTAL */
_tal void INIT_TAL_PTRS (short *, char *)
_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';
}
Considerations When Interfacing to pTAL 131