In the following example, a function is prototyped in a piece of
C++ code
and uses, by default,
C++ linkage.
void CXX_FUNC (int); // C++ linkage
Note that C++ is case-sensitive, but PL/I, COBOL, assembler,
and FORTRAN are not. In these languages, external names are mapped
to uppercase. To ensure that external names match across interlanguage
calls, code the names in uppercase in the C++ program, supply an
appropriate #pragma map specification, or use the NOLONGNAME compiler
option. This will truncate and uppercase names for functions without C++ linkage.
To reference functions defined in other languages, you should use
a linkage specification with a literal string that is one of the following:
- C
- COBOL
- FORTRAN
- OS
- OS_DOWNSTACK
- OS_NOSTACK
- OS_UPSTACK
- OS31_NOSTACK
- PLI
- REFERENCE
For example, the following specification declares the two functions
ASMFUNC1 and
ASMFUNC2 to
have operating system linkage. The function names are case-sensitive
and must match the definition exactly. You should also limit identifiers
to 8 or fewer characters.
extern "OS" {
int ASMFUNC1(void);
int ASMFUNC2(int);
}
Use the reference type parameter (type&) in C++ prototypes
if the called language does not support pass-by-value parameters or
if the called routine expects a parameter to be passed by reference.
Note: To have your program be callable by any of these other
languages, include an extern declaration for the function
that the other language will call.