Why a name that is not standardized

I'm just wondering why the name mangling has never been standardized by the C ++ standard. Obviously, different name change algorithms damage interoperability [1], and I see no advantage in determining its implementation.

That is, contrary to the statement of conditional conventions or the size of primitives, the machine itself does not care and does not even know what the function is called. So why hasn't it been standardized and why is it still not standardized? Compilers have changed the rules in the past anyway between versions.

[1] all those people who export functions as extern "C" speak volumes.

+24
c ++ name-mangling
Apr 12 2018-12-12T00:
source share
2 answers

The standard does not address implementation details. There are many, many things that depend on the implementation and which prevent collaboration programs: how classes are laid out, the vtable structure, etc. In general, compilers will change if they change any of them. This is intentional as it prevents code that will not work when linked.

It is possible for a particular platform to define C ++ ABI; all compilers that adhere to this will use compatible implementations and the usual name. This is a problem for platform providers, however; for some reason, very few vendors have defined C ++ ABI.

And the reason extern "C" is because almost all platforms define C ABI.

+19
Apr 12 2018-12-12T00:
source share

The standard does not actually require a name change. In this case, the Standard does not require IEEE floating-point numbers, or integers with two additions, or any number of other things.

Until there was a widespread ABI that he could rely on, GCC actually abandoned the use of a different name-switching scheme than its competitors:

g ++ does not handle the name in the same way as other C ++ compilers. This means that object files compiled with one compiler cannot be used with another.

This effect is intentional to protect you from more subtle issues. Compilers differ in many of the internal details of a C ++ implementation, including: how class instances are laid out, how multiple inheritance is implemented, and how virtual function calls are handled. If the encoding of the name was done the same way, your programs will link to libraries provided by other compilers - but then the programs will crash at startup. Incompatible libraries are then detected at connection time, and not at runtime.

The name mangling is also more complex than many programmers understand. For example, how would the standard indicate acceptable calling conventions for all platforms on which C ++ could work ? Should the RISC system support x86 stdcall , although RISC systems usually pass their arguments in registers rather than on the stack?

+15
Apr 12 2018-12-12T00:
source share



All Articles