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

PROC TAL^NAME (a);
INT .EXT a; !32-bit pointer
BEGIN
a[2] := 10;
END;
pTAL Procedures That You Cannot Call Directly
Your C program cannot directly call a pTAL procedure that returns both a value and a condition
code. To access a pTAL procedure that returns both a value and a condition code, you must write
a “jacket” procedure in pTAL that is directly callable by your C program. Define this jacket procedure
so that it:
Passes arguments from C calls through to the pTAL procedure unchanged
Returns the pTAL 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 pTAL source module that defines the jacket routine:
?SOURCE EXTDECS(GETPOOL);
INT 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);
if < then
return -1
else if > then return 1 else return 0;
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 *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 );
}
Techniques other than this cannot be used on TNS/E systems. For more details, see the Appendix
D of the pTAL Reference Manual.
Considerations When Interfacing to pTAL 129