View Full Version : #ifdef __cplusplus

09-29-2002, 08:51 AM
#ifdef __cplusplus
extern "C" {

what does this do?

09-29-2002, 09:46 AM
If you are writing a DLL, C++ will mangle the names of any exported functions. It does this to allow overloading.

The converse is true if you are importing functions into C++ from a C DLL or from a C++ DLL that was exported with the extern "C".

If you don't put the extern "C" on the prototypes of the imported functions, C++ assumes you are importing the mangled names, yet the DLL is exporting non-mangled names, so it will not be able to find it.

Hope that makes sense. http://www.opengl.org/discussion_boards/ubb/smile.gif

09-29-2002, 03:18 PM
Close, but not quite. This is necessary when calling C functions from C++ code. It has nothing to do with DLLs. Like you said, it is because of name mangling. DLL stands for Dynamic-Link Library, if you didn't know.

09-29-2002, 06:25 PM
Ok, so my description wasn't technically accurate, but it is the most common example of where it is used. This is also something that you find in static libraries. Also, since libraries are usually where you are going to use C functions in C++, it really isn't inacurate to describe how it's used in regard to DLLs.