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

then a C routine has limited access to the TNS C run-time library.
If a program uses the CRE, each routine in the program appears to be running in its own
language-specific run-time environment, regardless of the language of the main routine. For
example, if:
The main routine of a mixed-language program is written in COBOL
The program runs in the CRE
then a C routine has complete access to the TNS C run-time library.
D-series TNS C and Pascal run-time libraries always call CRE library routines for services managed
by the CRE; they can run only in the CRE. D-series TNS COBOL and FORTRAN run-time libraries
call CRE library routines if you compile all the routines in a program to run in the CRE. In contrast,
TAL routines must call CRE library routines directly.
For information on writing programs that use the services provided by the CRE, see the Common
Run-Time Environment (CRE) Programmer’s Guide. For more details on specifying a run-time
environment, see the description of pragma ENV (page 183). For more details on mixed-language
binding, see Restrictions on Binding Caused by the ENV Pragma (page 267).
Using Standard Files in Mixed-Language Programs
In a mixed-language program, if a TNS C function is to be the main function, it should be compiled
with the NOSTDFILES pragma to keep it from automatically opening the three standard C files:
stdin, stdout, and stderr.
If the main routine is not written in C, the three standard C files will not be automatically opened.
If you want any or all the standard files to be opened for C, you must explicitly open them by
calling the fopen_std_file() function.
Writing Interface Declarations
Your TNS C programs can call procedures written in C++, COBOL, FORTRAN, D-series Pascal,
and TAL, in addition to procedures written in an unspecified language type. You cannot mix TNS
and native-mode language modules.
All external procedures must be declared. The interface declaration indicates the correct language
or indicates "unspecified," if the language is unknown. If the language is unspecified, the external
procedure is assumed to be written in C.
Because lexical and operational features differ between C and these other languages, you must
use an interface declaration instead of a simple function declaration to declare a procedure written
in one of these other languages. Interface declarations are an HP extension to the ISO/ANSI C
standard for function declarations. They provide additions that account for most of the differences
between C and the other language.
The modern, preferred method for writing an interface declaration is to use a standard function
prototype followed later by a FUNCTION pragma. This is the general form:
int NAME (<params>);
...
#pragma function NAME (params)
For more details on syntax, see the pragma FUNCTION (page 195). For an illustration of a
FUNCTION pragma used in an interface declaration, see the examples following this discussion.
98 Mixed-Language Programming for TNS Programs