0

Is there a way to identify where the virtual pointers reside (by generating a mask or so) in the memory layout? (ex: Below code)

class D{//virtual functions}
class B{//virtual functions}
class A : public B, public D
{//virtual functions}
Sanka Darshana
  • 1,391
  • 1
  • 23
  • 41
  • Possibly, but it is generally platform dependent, so you'd need to specify OS, compiler, version at least. – Retired Ninja Mar 23 '15 at 06:09
  • let's say SUSE Linux, gcc 4.3.4. But I'm searching for the idea behind rather than the implementation. Thanks. – Sanka Darshana Mar 23 '15 at 06:16
  • This may help: http://stackoverflow.com/questions/1905237/where-in-memory-is-vtable-stored or you can search for vtable and sort through the results. – Retired Ninja Mar 23 '15 at 06:18
  • You can reasonably guess that pointers to the virtual dispatch table will either be at the start or end of objects. Using `offsetof` to check whether the first data member is at 0 or after a gap typically lets you infer which, though it's left as undefined behaviour by the Standard. Tends to work on actual compilers though - anything you do with this information's undefined anyway, so I doubt you'd care.... – Tony Delroy Mar 23 '15 at 07:33
  • Doesn't offsetof require types without virtual functions? Also biggest problem is dealing with the multiple inheritance. :) – Sanka Darshana Mar 23 '15 at 10:41

0 Answers0