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

7 Mixed-Language Programming for TNS Programs
This chapter describes the Common Run-Time Environment (CRE) and the C interface declarations
that are necessary to interface to other programming languages. The CRE and C interface
declarations are HP features for NonStop systems that are not available in standard ISO/ANSI C.
TNS programs in the Guardian environment can contain routines written in TNS COBOL, FORTRAN,
TAL, TNS C, and D-series Pascal. TNS programs in the OSS environment can contain routines
written in TNS COBOL, TAL, TNS C, and TNS C++.
Applications that include modules written in other languages can also be compiled in the Guardian
environment to run in the OSS file system (see Binding a C Module (page 264)). For a comparison
of TNS and TNS/R native mixed-language programming, see Differences Between Native and
TNS Mixed-Language Programs (page 139).
Introducing the CRE
The Common Run-Time Environment (CRE) is a set of services that supports mixed-language
programs. The CRE library is a collection of routines that implements 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.
C-series programs run in a language-specific run-time environment. D-series C and Pascal programs
run only in the CRE. D-series COBOL, FORTRAN, and TAL programs can run in either their
language-specific run-time environments or the CRE. All the routines in a program must be compiled
to run in either a language-specific run-time environment or the CRE.
Table 21 lists the C-series and D-series run-time environments available for each language.
Table 21 Run-Time Environments Available
D-Series EnvironmentsC-Series EnvironmentLanguage
CREC run-time environmentC
CRE or COBOL run-time environmentCOBOL run-time environmentCOBOL
CRE or FORTRAN run-time environmentFORTRAN run-time environmentFORTRAN
CREPascal run-time environmentD-series Pascal
CRE or no run-time environmentNo run-time environmentTAL
The language of a program’s main routine determines the program’s run-time environment. (The
main routine is the routine that executes first in your program; it is the routine declared with the
main keyword, or in some languages the PROGRAM keyword.)
If a program does not use the CRE, routines written in a language other than that of the main
routine have limited access to their run-time libraries. For example, if:
The main routine of a mixed-language program is written in COBOL
The program runs in a language-specific run-time environment (the COBOL run-time
environment)
Introducing the CRE 97