C/C++ Programmer's Guide (G06.25+)

Mixed-Language Programming for TNS/R and
TNS/E Native Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-008
8-14
Considerations When Interfacing to pTAL
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 on page 8-17.)
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;