While porting such applications, if developers have to intermix C and C++ code, they then have to depend on C++ language features like extern "C" for giving C linkage to some set of @@ -32,7 +32,7 @@ It applies when the developer tries to use C APIs by including corresponding headers. To avoid name mangling, the developer should mention explicitly that those APIs are C APIs, by using the extern "C" keyword.
The syntax of extern "C" is shown below:
The declaration (or definition) that immediately follows extern "C" has the C linkage.
Everything between the curly braces has C linkage, unless declared otherwise.
While writing header files with C functions which will be included by both C and C++ source files, the user must use extern "C" properly. See the example below:
The developer can use all the features of C++ except templates within C by giving those functions extern "C" linkage. See the example below: