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-13
Sharing Data
To illustrate this technique, the following 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,
thus 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_eg(c_code))
return( (short *)blk_addr );
else
return( NULL );
}
Sharing Data
You can share global data in the user data segment between the following kinds of TAL
and TNS C modules:
•
TAL modules that declare global variables having standard indirection (.)
•
TNS C small-memory-model modules