I’m just wondering why name mangling was never standardized by the C++ standard. Clearly having different name mangling algorithms hurts interoperability[1] and I don’t see any advantage of having it implementation-defined.
That is, contrary to say calling conventions or size of primitives the machine itself doesn’t care or even know how the function is called. So why wasn’t it standardized and why is it still not standardized? Compilers have changed the rules in the past anyhow between versions.
[1] all those people exporting functions as extern "C" speak volumes.
The standard does not address implementation details. There are many,
many things which depend on the implementation, and which prevent
programs from working together: how the classes are laid out, the
structure of the
vtable, etc. In general, compilers will change thename mangling if they change any of these. This is intentional, as it
prevents code which would not work from linking.
It is possible for a given platform to define a C++ ABI; all compilers
which adhere to it would use compatible implementations, and have a
common name mangling. This is an issue for the platform vendors,
however; for whatever reasons, very few vendors have defined a C++ ABI.
And the reason
extern "C"works is because almost all platforms define a C ABI.