HP aC++/HP C A.06.20 Programmer's Guide
function_declaration2
...
function_declarationN
}
Examples of extern "C"
The following declarations are equivalent:
extern “C” char* get_name(); // declare the external C module
and
extern “C”
{
char* get_name(); // declare the external C module
}
You can also use a linkage directive with all the functions in a file, as shown in the
following example. This is useful when you use C library functions in a C++ program.
extern “C”
{
#include “myclibrary.h”
}
NOTE: Do not use extern "C" when you include standard C header files. These
header files already contain extern "C" directives.
Although the string literal following the extern keyword in a linkage directive is
implementation-dependent, all implementations must support C and C++ string literals.
Refer to linkage specifications in The C++ Programming Language, Third Edition for more
information.
Differences in Argument Passing Conventions
When your C++ code calls functions written in C, ensure that the called C functions do
not use function prototypes that suppress argument widening. If they do, your C++
code passes arguments wider than the expectations of your C code.
The main() Function
When you mix C++ modules with C modules, the overall control of the program must
be written in C++. The main function should appear in a C++ module, rather than in a
C module. There are two exceptions:
1. C++ programs and libraries, including HP-supplied libraries, without any global
class objects containing constructors or destructors.
2. C++ programs and libraries, including HP-supplied libraries, without static objects.
Data Compatibility between C and C++ 247