Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
405 views
in Technique[技术] by (71.8m points)

c++ - Why is name mangling not standardized

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 the name 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...