Extern “C” and Name Mangling

Name mangling is very common in C++ compilers when a function have the same name with different parameters or overloading.

As the compiler compiles your code, with a function with the same name , the compiler tries to rename the function or method so they dont clash with each other at runtime and providing different signature.

Using Extern “C” on the other hand if you are calling a C function exactly as it is from your C++ code. With a syntax of

extern “C” statement or block of code

This prevent the compiler from mangling the name at compile time otherwise getting bunch of errors and crashes.

Here are some good articles about it:
http://www.geeksforgeeks.org/extern-c-in-c/

Here some good link about Calling Convention: eg. __stdcall, __cdecl
http://blog.aaronballman.com/2011/04/the-importance-of-calling-conventions/

Leave a Reply

Your email address will not be published. Required fields are marked *