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

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 this 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
name x;
int i; extern short i;
int j; extern short j;
int k [0:2] = 'P' := [0, 1, 2]; extern const short k [3] := {0, 1, 2};
block b;
int .ext p; extern short* p;
int .ext s (template); extern Template s;
end block;
block c;
struct s1 (template); extern Template s1
int a [0:1]; extern short a [2];
end block;
If you want variable definitions to be in the C++ source, remove the extern specifier and change
the pTAL source to ?NOEXPORTGLOBALS.
132 Mixed-Language Programming for TNS/R and TNS/E Native Programs