C++ v-table: Part of the language or compiler dependent?

我的未来我决定 提交于 2019-11-27 05:59:51

问题


Is the v-table (virtual method table) a part of the C++ specification, or is it up to the compiler to solve the virtual method lookups?

In case it's part of the spec: Why?

I'd guess that it's compiler dependent, but someone said to me that it's part of the spec.

References are very welcome!


回答1:


1.7 The C++ memory model 3 [...] Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation. [...]

There you have it. It is up to the implementation.




回答2:


No, it's not part of the language specification. The standard specifies how calls to virtual functions must be resolved but not the mechanism that compiler implements to achieve the required results.

It's difficult to provide a "negative" reference (i.e. to where the standard doesn't mandate a v-table) but the relevant parts of the standard for virtual function calls are 5.2.2 [expr.call] and 10.3 [class.virtual].



来源:https://stackoverflow.com/questions/3674929/c-v-table-part-of-the-language-or-compiler-dependent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!