为什么名称调整不标准化 [英] Why is name mangling not standardized

查看:158
本文介绍了为什么名称调整不标准化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道为什么名称调整从来没有标准化的C ++标准。显然有不同的名称调整算法损害互操作性[1],我没有看到任何优点,它的实现定义。

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]所有这些人导出函数为 externC

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

推荐答案

标准不涉及实现细节。有很多,
许多事情,这取决于实现,并阻止
程序一起工作:如何布局,
结构的 vtable 等。一般来说,编译器将更改
名称修改,如果他们更改任何这些。这是有意的,因为它
防止无法链接的代码。

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.

给定平台可以定义一个C ++ ABI;所有的编译器
遵守它将使用兼容的实现,并有一个
通用名称。这是平台供应商的一个问题,
然而;无论什么原因,很少有供应商定义了一个C ++ ABI。

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.

原因 externC因为几乎所有平台都定义了一个C ABI。

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

这篇关于为什么名称调整不标准化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆