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-13
Considerations When Interfacing to pTAL
SHARED2 alignment rules that are the AUTO rules for TNS platforms, and directs the
native C and C++ compilers to lay out components using the AUTO alignment rules for
their respective TNS/R and TNS/E platforms.
Sharing pTAL Data With C Using Pointers
To share pTAL global data with C modules, follow these steps:
1. In the pTAL module, declare the data using C-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.)
2. In the C module, declare pointers to the data, using pTAL-compatible data types.
3. In the C module, declare a routine to which pTAL can pass the addresses of the
shared data.
4. In the C routine, initialize the pointers with the addresses sent by the pTAL module.
5. Use the pointers in the C module to access the pTAL data.
The following example shows how to share pTAL data with a C module. The pTAL
module passes to a C routine the addresses of two pTAL arrays. The C routine assigns
the array addresses to C pointers.
C Code
short *c_int_ptr; /* pointer to pTAL data */
char *c_char_ptr; /* pointer to pTAL data */
short INIT_C_PTRS (short *tal_intptr, char *tal_strptr)
{ /* called from pTAL */
c_int_ptr = tal_intptr;
c_char_ptr = tal_strptr;
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;