Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

vtable

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!

like image 554
aioobe Avatar asked Sep 09 '10 08:09

aioobe


2 Answers

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.

like image 178
dirkgently Avatar answered Oct 20 '22 17:10

dirkgently


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].

like image 41
CB Bailey Avatar answered Oct 20 '22 19:10

CB Bailey