What does the vtable look like?

Jody Hagins jody@atdesk.com
Fri Jun 11 07:12:00 GMT 1999


With cfront, I can get the virtual function table like so...


struct Virtual_Function_Table_Entry
{
  short d;
  short i;
  int (*f)();
};

The virtual table pointer stored in each object points to an array of
Virtual_Function_Table_Entry structures.

Then I can run through all the virtual functions like so...

class VBase
{
public:
  virtual ~VBase();
};

VBase::
~VBase()
{
}

void print_virtual_functions(VBase * p)
{
  Virtual_Function_Table_Entry * vtbl =
      *((Virtual_Function_Table_Entry**)p);
  for (int i = 0; vtbl[i].f; ++i)
  {
    cout << "virtual function " << i << " is "
         << vtbl[i].f << endl;
  }
}




For egcs, what does the virtual table pointer point to?  Is it a table of
pointers, structures, a linked list of pointers?  What is it?


Thanks!



More information about the Gcc mailing list