C/C++ Programmer's Guide (G06.25+)
Mixed-Language Programming for TNS/R and
TNS/E Native Programs
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
8-5
Declaring External Routines
•
If the pTAL definition specifies the EXTENSIBLE attribute, the interface declaration
must specify _extensible.
•
If the pTAL definition specifies the VARIABLE attribute, the interface declaration
must specify _variable.
Examples
1. This example, taken from the stdlib.h header file, shows the preferred style for
declaring an external routine (in this case, for the CRE_ASSIGN_MAXORDINAL_
procedure). The declaration consists of a standard function prototype and a
FUNCTION pragma:
void get_max_assign_msg_ordinal (void);
...
#pragma function get_max_assign_msg_ordinal
(alias(“CRE_ASSIGN_MAXORDINAL_”), extensible, tal)
The example above is equivalent to the following interface declaration:
_extensible _tal _alias (“CRE_ASSIGN_MAXORDINAL_”)
get_max_assign_msg_ordinal (void);
2. This example, taken from the cextdecs header, shows the interface declaration
for the CHANGELIST system procedure. Notice that identifier names in the
parameter type list are optional, because C cares only about the types of the
parameters:
_tal _variable _cc_status CHANGELIST(short, short, short);
3. This example shows you how to use the _cc_status type specifier while also
using a function prototype and a FUNCTION pragma to declare an external
procedure.
Notice that the variable c_code is declared as type _cc_status so that it can be
compared against the condition code that is contained in the _status_eq()
macro:
#include <tal.h> /* defines _cc_status and _status_eq */
_cc_status C_GETPOOL (short *pool_head,
long block_size,
long* block_addr);
#pragma function C_GETPOOL (tal, alias("C^GETPOOL"))
short *pool_alloc ( short *my_pool, long size )
{
_cc_status c_code;
long blk_addr;
c_code = C_GETPOOL(my_pool, size, &blk_addr);
if (_status_eq(c_code))
return( (short *)blk_addr );