A
C++ function is not necessarily made C-callable by prototyping the
C++ function with the extern "C" keywords. While the extern "C" keyword prevents the name of the
C++ from being mangled, there are other issues to be considered.
|
|
C does not use classes. Therefore, it cannot pass classes by value. If a
C++ API function requires that a class be passed by value as its input, it is not C callable, regardless of whether it is prototyped with the extern "C" keyword. This leads to the following rule: API functions must not pass classes by value.
|
|
C does have
void pointers. A C
void pointer points to the address of a class just as it points to a structure. Therefore, a
C++ API function would be C-callable if its class arguments were passed by address (BODY*) or by reference (BODY&). Either method allows the API function to be called from C.
|