C/C++ Programmer's Guide (G06.25+)
TNS C++ Implementation-Defined Behavior
HP C/C++ Programmer’s Guide for NonStop Systems—429301-008
B-3
Interfacing to the Standard C Run-Time Library
In the Guardian environment, Cprep truncates the UNIX named iostream header file
from iostream.h to iostreah to comply with the Guardian file naming conventions.
However, for portability, you can use iostream.h.
Interfacing to the Standard C Run-Time Library
To declare a standard C run-time library function, use the #include preprocessor
directive to include the name of the header file that contains the function prototype for
the particular function.
For example:
#include <stdio.h>
Interfacing to User-Defined C Libraries
If you have user-defined C function prototypes defined in a header file, designate the
header file as having C linkage. Therefore, use the extern C construct. For example:
extern "C" {
#include "myclib.h"
}
Interfacing to User-Defined C Functions
To declare a user-defined C function, you can use the C++ extern C construct, which is
a standard C++ language feature. Here is an example of using the extern C construct
to declare a user-defined C function:
extern "C" void f(int);
If you want to declare several user-defined C functions at the same time, you can use
braces. For example,
extern "C" {
void f(int);
int g(char);
}
The extern C construct states that the specified functions are C functions so that there
is no name encoding. If you do not include the user defined C function in the extern C
construct, you will get errors when Binder tries to bind a module that contains these
functions.
In C++, function names are encoded or mangled to produce unique internal names,
which incorporate function argument types. In C there is no name encoding. Therefore,
if you want to call a C function, its name will not be the same as that produced by the
C++ translator and used by the Binder. To indicate that C linkage applies, rather than
C++, you must use the extern C construct.