C/C++ Programmer's Guide (G06.25+)
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
7-14
Sharing Data
You can share global data in the automatic extended data segment between the
following kinds of TAL and C modules:
•
TAL modules that declare global variables having extended indirection (.EXT)
•
TNS C large-memory-model modules
In a large-memory-model TNS C module, you can use the _lowmem storage class
specifier to allocate a C array or structure that can be represented by a 16-bit address
if needed in a call to a TAL routine or a system procedure.
Using pointers to share data is easier and safer than trying to match declarations in
both languages. Using pointers also eliminates problems associated with where the
data is placed.
To share data by using pointers, first decide whether the TAL module or the TNS C
module is to declare the data:
•
If the TAL module is to declare the data, follow the guidelines in Sharing TAL Data
With TNS C Using Pointers on page 7-14.
•
If the TNS C module is to declare the data, follow the guidelines in Sharing TNS C
Data With TAL Using Pointers on page 7-15.
Sharing TAL Data With TNS C Using Pointers
To share TAL global data with TNS C modules, follow these steps:
1. In the TAL 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 Variables and Parameters on page 7-17.)
When you declare TAL arrays and structures, use indirect addressing.
2. In the TNS C module, declare pointers to the data, using TAL-compatible data
types.
3. In the TNS C module, declare a routine to which TAL can pass the addresses of
the shared data.
4. In the C routine, initialize the pointers with the addresses sent by the TAL module.
5. Use the pointers in the TNS C module to access the TAL data.
The following example shows how to share TAL data with a large-memory-model TNS
C module. The TAL module passes to a C routine the addresses of two TAL arrays.
The C routine assigns the array addresses to C pointers.
C Code
short *c_int_ptr; /* pointer to TAL data */
char *c_char_ptr; /* pointer to TAL data */
short INIT_C_PTRS (short *tal_intptr, char *tal_strptr)
{ /* called from TAL */
c_int_ptr = tal_intptr;
c_char_ptr = tal_strptr;