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

To access a TAL procedure that both returns a value and sets a condition code, you must write a
“jacket” procedure in TAL that is directly callable by your TNS C program. You define this jacket
procedure so that it:
Passes arguments from C calls through to the TAL procedure unchanged
Returns the TAL procedures return value indirectly through a pointer parameter
Returns the condition code using the function-return type _cc_status
To illustrate this technique, this example defines a jacket procedure for the GETPOOL system
procedure. First, here is the TAL source module that defines the jacket routine:
?SOURCE EXTDECS(GETPOOL);
PROC C^GETPOOL(pool^head, block^size, block^addr);
INT .EXT pool^head; ! Address of pool head
INT(32) block^size; ! Block size
INT(32) .block^addr; ! Block address
BEGIN
! Call GETPOOL, storing return value in block^addr
block^addr := GETPOOL(pool^head, block^size);
RETURN; ! No return value here
END;
The definition of C^GETPOOL declares the same parameters as the GETPOOL system procedure,
with the addition of block^addr. This additional parameter is a pointer to the return type of
GETPOOL, which is INT(32). Note that the RETURN statement specifies no return value and that
it immediately follows the GETPOOL call, therefore ensuring that the condition code is unchanged.
Here is the interface declaration for C^GETPOOL as you would enter it in your C module:
_tal _cc_status _alias ("C^GETPOOL") C_GETPOOL
(short _far *pool_head,
long block_size,
long *block_addr);
Once you have made this declaration, you can effectively call GETPOOL by calling the jacket
routine C_GETPOOL; for example:
short *pool_alloc(long size)
{
short c_code;
long blk_addr;
c_code = C_GETPOOL(my_pool,size,&blk_addr);
if (_status_eq(c_code))
return( (short *)blk_addr );
else
return( NULL );
}
Sharing Data
You can share global data in the user data segment between these types of TAL and TNS C
modules:
TAL modules that declare global variables having standard indirection (.)
TNS C small-memory-model modules
You can share global data in the automatic extended data segment between these types of TAL
and C modules:
TAL modules that declare global variables having extended indirection (.EXT)
TNS C large-memory-model modules
106 Mixed-Language Programming for TNS Programs