11

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!

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • Just out of interest ... how else would you implement it? – Goz Sep 09 '10 at 08:29
  • There are a few alternatives listed in the wikipedia-article actually. – aioobe Sep 09 '10 at 08:38
  • 4
    Because you can't tell how technology will change the standard writers deliberately try not define HOW things happen but rather try and define WHAT things should happen. If you define HOW things should work you are painting yourself into a corner with new techniques or the ability to use new technology. – Martin York Sep 09 '10 at 09:27

2 Answers2

15

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.

Alex B
  • 82,554
  • 44
  • 203
  • 280
dirkgently
  • 108,024
  • 16
  • 131
  • 187
  • You have a URL for that quote? ([This one](http://www.kuzbass.ru:8086/docs/isocpp/) doesn't say the same thing). – aioobe Sep 09 '10 at 08:44
  • No, but you can download n3092.pdf. I am not sure which version of the draft/which Standard that link refers to. (It doesn't even open for me!) – dirkgently Sep 09 '10 at 08:51
  • 4
    Worth emphasizing that n3092.pdf is the draft for the _next_ version of C++ (C++0x) and not a draft of the current standard. – CB Bailey Sep 09 '10 at 08:53
5

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

CB Bailey
  • 755,051
  • 104
  • 632
  • 656