2012-01-03 wcdj
Question:
What's the theory behind this: #ifdef __cplusplus extern "C" {I have been meeting the following in some c/c++ codes but I don't understand the theory behind it:
#ifdef __cplusplus
extern "C" {
#endif
I want to understand how it works. I know about the preprocessing but I don't know what that extern "C" in the code does. Someone teach me please!
Answers 1:
The C++ compiler does something called name mangling which facilitates function overloading.The extern "C" syntax tell the C++ compiler not to perform function overloading.
The code snippet that you posted first checks if the code being compiled is using a C++ compiler and if so starts a block in which name mangling will not be done.
Answer 2:
That typically encloses DLL's exported functions.You should know, C Language and C++ one use different approach