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-2
Introducing the CRE
native COBOL. The main() function in a native mixed-language program can be
written in native C or C++, native COBOL, but not pTAL.
Introducing the CRE
The Common Run-Time Environment (CRE) is a set of services that support mixed-
language programs. The CRE library is a collection of routines that implement the
CRE. The CRE library enables the language-specific run-time libraries to coexist
peacefully with each other. User routines and run-time libraries call CRE library
routines to access shared resources managed by the CRE, such as the standard files
(input, output, and log) and the user heap, regardless of language.
The CRE does not support all possible operations. For example, the CRE supports file
sharing only for the three standard files: standard input, standard output, and standard
log. The language-specific run-time libraries access all other files by calling Guardian
system procedures directly, whether or not a program uses the CRE.
All native mixed-language programs run in the CRE environment. Existing TAL code
that is converted to pTAL must also be converted to run in the CRE. For more
information on writing programs that use the services provided by the CRE, refer to the
Common Run-Time Environment (CRE) Programmer’s Guide.
Using Standard Files in Mixed-language
Programs
In a mixed-language program, if a 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 of the standard files to be opened for C, you must
explicitly open them by calling the fopen_std_file() function.
Declaring External Routines
Your native C and C++ programs can call procedures written in COBOL and pTAL, as
well as procedures written in an unspecified language type. You cannot mix TNS and
native mode languages.
All external procedures must be declared. When interfacing to pTAL or an unspecified
language, you must declare the external procedure appropriately because lexical and
operational features differ between C or C++ and other languages. There are two ways
to declare an external function: using a function prototype and a FUNCTION pragma
(the preferred method), and using an interface declaration (the traditional method).