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 Systems429301-008
8-3
Declaring External Routines
Writing Interface Declarations
The interface declaration is an HP extension of the function declaration as defined by
ISO/ANSI C. The interface declaration indicates the correct language or indicates
unspecified if the language is unknown. If no language attribute specifier is provided,
then the external procedure is assumed to be written in the same language as the
compilation.
After providing an interface declaration, your C or C++ program uses normal function
calls to access the procedure written in the other language. However, remember that
these calls cross language boundaries; thus, there are restrictions beyond those of
normal C function calls.
The interface declaration enables you to declare COBOL procedures and most kinds of
pTAL procedures, including:
pTAL procedures defined with the VARIABLE or EXTENSIBLE attribute
Procedures whose names are not valid C identifiers
pTAL procedures that do not return a value but do return a condition code
However, your C or C++ program cannot directly call a pTAL procedure that returns
both a value and a condition code. The subsection pTAL Procedures That You Cannot
Call Directly on page 8-10 presents techniques that enable your C or C++ program to
access pTAL procedures that fall into this category.
Using a Function Prototype and a FUNCTION Pragma
The recommended method for declaring an external routine is to use a standard
function prototype followed later by a FUNCTION pragma.
For details on syntax, see the description of pragma FUNCTION on page 13-36 and for
illustrations of FUNCTION pragmas used in interface declarations, see the Examples
on page 8-5.
Using an Interface Declaration
The traditional method for declaring external routines is to use an interface declaration
in which you declare the procedure as if it were a C function, except that you include:
A language attribute specifier (_cobol, _tal or _unspecified) to identify the
language of the external procedure. For native C and C++, _tal denotes the pTAL
language on both TNS/R and TNS/E systems.
An _alias attribute specifier to assign the external name, or rather the name as
known to the other language.
The syntax for these older-style interface declarations is described in Attribute Specifier
on page 2-10. However, it is recommended that you use the FUNCTION pragma to
declare external routines.