Doesn't extern "C" remove name mangling? |
Yes it does, but there's more a DLL than name mangling.
A DLL can export data, functions and classes. We folk always think exporting data is a bad idea.
Functions can be exported by name or by ordinal. It takes longer to search for a function name, than to look up a number. So back in WIN16, functions were looked up by name because the hardware was so slow.
It was with great relieve that C++ mangled symbols can be exported as easily as C symbols. And as long as you're interfacing with C++ systems built from the same mangling scheme, things are ok (heaps aside).
It turns out that classes can be exported too. If you look at the runtime libraries for MFC, you'll seem lots of exported classes and their members.
Finally, it's possible for your DLL to export interfaces with a C factory function. A C++ client can obtain an interface from the factory and make no further deman on the DLL interface mechanism.
So what makes this all so vendor specific?
1. Each vendor typically has their own name mangling scheme.
2. Each vendor typically has their own vtable scheme?
3. Heap arrangements.
Obviously, if a client cannot understand the naming convention of the code in the DLL, they're incompatible.
If the client and DLL have different vtable implementations, then they cannot use Object Oriented features; they can use STL but not streams for example.
Finally, what does
int* a = int(f(x));
and
delete [] a;
mean when placed in a header file? One has to be careful. Do the new and delete refer to the same heap? They'd better. The implementation can go some way to help, but it's not always obvious what's right.
The operation system's native language is C. So what if you want to use C++ in a system wide way? The answer is COM. With reference to the 3 issues listed above:
It turns out that classes are identified by GUIDs, large unique numbers. Methods are offsets within each class. There's no generalization, only composition.
Almost coincidentally, the method ordering scheme with a class in COM, matches exactly the vtable scheme in Microsoft's compiler. Amazing!
Early COM interfaces supported different heaps (IMalloc), but that idea was dropped for the greater good.
I think that about covers it.