Am I mistaken?
I understand that extern "C" prevents name mangling... but C++ doesn't just mangle names for the hell of it, it does it because it has to in order to allow for things like function overloading.
For example a C++ program can have any number of functions named "foo":
// ... etc
These are all distinctly different functions and therefore must all be exported under different names. They obviously cannot all be exported as "foo". As a result their names have to be mangled to retain scope/type information.
And how would you export something like an overloaded operator without mangling?
std::ostream& operator << (std::ostream&, const SomeType&);
The whole point of preventing name mangling (I thought) was to have C++
compiled code able to link to C
libraries (hence the name 'extern "C"
' and not 'extern "nomangle"')
If you're not going to put C code in the extern C block... then what's the point?
|How would you otherwise create an object in the library that is dynamically loaded during run-time? |
You'd do it the same way you're doing it now... you'd just remove the
part. C++ names can still be externally linked, their names will just be mangled.
|L B wrote:|
|C++ code is used in extern "C" all the time. |
Can you give me an example of a library that does this? I have never seen it.