What does the vtable look like?

Jody Hagins jody@atdesk.com
Wed Jun 30 15:43:00 GMT 1999

> > Unfortunately, there does not appear to be a terminator of the list.
> > I would think that the null would come at the *end* of the table,
> > not the beginning.  Or, at least some count, indicating the size of
> > the table...
> Nope.  It is a waste of space.  You cannot meaningfully for anything
> with the table without knowing how many elements are in the table.
> You will have to find that information out some other way.  One
> thought, is to put more member info into the rtti data, and then you
> could use it.


One thing that has me stumped is that if I get the "index" of the virtual

typedef int (Base::*Function)();

union U
  Function ff;
  void * vp;
  U u;
  u.ff = (Function)(&Base::something);
  cout << "Base::something -------->  " << u.vp << endl;

This is soming back as 0x00040000, but it's place in the table is actually index 3, but that is including the size and rtti info.  For example...

vtbl[0] = (nil)		-- offset to object
vtbl[1] = 0x8049430	-- rtti
vtbl[2] = 0x80493ec	-- Base::~Base()
vtbl[3] = 0x8048ee8	-- Base::something()
vtbl[4] = 0x8049308	-- Base::bar_event_handler()
vtbl[5] = 0x80492d0	-- Base::foo_event_handler()

&Base::something inside class = 0x8048ee8
&Base::something -------->  0x40000

This seems to indicate that something can be found at index 4, but this is not the case.  I must still be missing something...

More information about the Gcc mailing list