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

Table Of Contents
Mixed-Language Programming for TNS Programs
HP C/C++ Programmer’s Guide for NonStop Systems429301-010
7-17
Variables and Parameters
Sharing TAL Data With TNS C Using BLOCK Declarations
As of the D20 release, TAL modules can share global data with TNS C modules by
declaring each shared variable in its own BLOCK declaration and giving both the
variable and the BLOCK the same name. The TNS C modules must also declare each
shared variable; the layout of the variable must match in both the TAL and C modules.
In this example, a TAL module declares a variable within a BLOCK declaration, and the
TNS C module declares the equivalent variable:
TAL Code C Code
NAME TAL_module;
BLOCK fred;
INT .EXT fred; int FRED; /*all uppercase*/
END BLOCK;
Because this method requires that the layout of the corresponding TAL and C
declarations match, it is recommended that you share data by using pointers where
possible.
Variables and Parameters
This subsection gives guidelines for declaring compatible TAL and C variables and
parameters. These guidelines supplement those given in Sharing TAL Data With TNS
C Using BLOCK Declarations on page 7-17. The topics are discussed are:
STRING and char variables
Arrays
Structures
Multidimensional arrays
Arrays of structures
Redefinitions and unions
Pointers
Enumeration variables
Bit-field manipulation
UNSIGNED variables and packed bit fields
TAL routines as parameters to C
C routines as parameters to TAL
When you declare formal reference parameters, remember to use indirection:
If the caller is a small-memory-model TNS C routine, use standard indirection (.)
for the TAL formal parameter.
If the caller is a large-memory-model TNS C routine, use extended indirection
(.EXT) for the TAL formal parameter.