C++ Migration Guide

Linking to C Functions

The compiler encodes C++ function names to allow overloading. To call a C function, or a C++ function "masquerading" as a C function, you must prevent this encoding. Do so by using the extern "C" declaration. For example:


extern "C" { 
double sqrt(double); //sqrt(double) has C linkage 
    } 

This linkage specification does not affect the semantics of the program using sqrt(), but simply causes the compiler to use the C naming conventions for sqrt().

Only one of a set of overloaded C++ functions can have C linkage. You can use C linkage for C++ functions that you intend to call from a C program, but you would only be able to use one instance of that function.

You cannot specify C linkage inside a function definition. Such declarations can only be done at the global scope.