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-13
TAL Procedures That You Cannot Directly Call
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_eg(c_code))
return( (short *)blk_addr );
else
return( NULL );
}