Technical data
Interlanguage Communication [9]
In some situations, it is necessary or advantageous to make calls to assembly
or Fortran functions from C or C++ programs. This chapter describes how to
make such calls. It also discusses calls to C and C++ functions from Fortran and
assembly language. For additional information on interlanguage communication,
see
Interlanguage Programming Conventions. The calling sequence is described
in detail on the callseq(3) man page, which is included in the Application
Programmer’s Library Reference Manual.
The C and C++ compilers provide a mechanism for declaring external functions
that are written in other languages. This allows you to write portions of an
application in C, C++, Fortran, or assembly language. This can be useful in
cases where the other languages provide performance advantages or utilities
that are not available in C or C++.
This section describes how to call assembly language and Fortran programs from
a C or C++ program. It also discusses the issues related to calling C or C++
programs from other languages. These calls apply to UNICOS and UNICOS/mk
systems unless stated otherwise.
9.1 Calls between C and C++ Functions
The following requirements must be considered when making calls between
functions written in C and C++:
• In Cray Standard C++, the extern "C" storage class is required when
declaring an external function that is written in Cray C or when declaring a
Cray Standard C++ function that is to be called from Cray C. Normally
the compiler will mangle function names to encode information about the
function’s prototype in the external name. This prevents direct access to these
function names from a C function. The extern "C" keyword will prevent
the compiler from performing name mangling.
• The program must be linked using the CC(1) command.
Objects can be shared between C and C++. There are some Cray Standard C++
objects that are not accessible to Cray Standard C functions (such as classes). The
following object types can be shared directly:
• Integral and floating types.
S–2179–36 123










