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 Systems—429301-008
8-15
Considerations When Interfacing to pTAL
charr[2] = 'B';
}
pTAL Code
INT .EXT tal_int_ptr; !Pointer to C data
STRING .EXT tal_char_ptr; !Pointer to C data
PROC init_tal_ptrs (c_addr1, c_addr2); !Called from C
INT .EXT c_addr1;
STRING .EXT c_addr2;
BEGIN
@tal_int_ptr := @c_addr1;
@tal_char_ptr := @c_addr2;
END;
PROC tal^name;
BEGIN
tal_int_ptr[0] := 10;
tal_int_ptr[2] := 20;
tal_char_ptr[2] := "A";
END;
Sharing pTAL Data With C Using BLOCK Declarations
pTAL modules can share global data with C modules by declaring each shared
variable in its own BLOCK declaration and giving both the variable and the BLOCK the
same name. The C modules must also declare each shared variable; the layout of the
variable must match in both the pTAL and C modules.
In the following example, a pTAL module declares a variable within a BLOCK
declaration, and the C module declares the equivalent variable:
pTAL Code C Code
NAME TAL_module;
BLOCK fred;
INT .EXT fred; int FRED; /*all uppercase*/
END BLOCK;
Because the preceding method requires that the layout of the corresponding pTAL and
C declarations match, it is recommended that you share data by using pointers where
possible.
Sharing pTAL Global Data With C/C++ Using BLOCK
Declarations
The pTAL directive BLOCKGLOBALS can be used to interface pTAL global data
declarations with C/C++. BLOCKGLOBALS directs the pTAL compiler to separate
implicitly all data declarations into individual blocks. For example:
pTAL Code C/C++ Code
?BLOCKGLOBALS
?EXPORTGLOBALS