extern "C" void foo(int);
extern "C"
{
void g(char);
int i;
}
When C++ compiler compiles the function It mangles the function name fot to support function overloading.
extern C is used mainly to inform compiler compile this in c style (i.e. do not do name mangling to function name.).
Mainly extern is used to when u have library compiled by C compiler. and want to add same in C++ code. When u compile it will get linking error because C++ compiler will mangle function name and C++ linker will not get the definition for the function name ( function definition is in C compiled library where function name is not mangled so.)
extern "C" with braces tells the C++ compiler do not mangle the function name.
0 comments:
Post a Comment