[C++ PATCH] ctor vtable vcall offsets

Mark Mitchell mark@codesourcery.com
Tue Feb 27 10:21:00 GMT 2001


>>>>> "Nathan" == Nathan Sidwell <nathan@codesourcery.com> writes:

    3.2.4 Caller

   When calling a virtual function f, through a pointer of static type
   B*, the caller
     * Selects a (possibly improper) subobject A of B such that A
       declares f. (In general, A may be the same as B.) (Note that A
       need not define f; it may contain either a definition of f, or a
       declaration of f as a pure virtual function.)
     * Converts the B* to point to this subobject. (Call the resulting
       pointer `a'.)
     * Uses the virtual table pointer contained in the A subobject to
       locate the function pointer through which to perform the call.
     * Calls through this function pointer, passing `a' as the this
       pointer.

I think that's a little imprecise.  (I wrote that language, so I can
safely criticize it...)

I think that `declares f' was supposed to mean `has an entry for f in
its vtable'.  For example, given:

  struct S { virtual void s(); };
  struct T { virtual void t(); };
  struct U : public S, public T {};

  U* up = new U;
  up->t();

You have to convert `up' to `T*' so that you can find an entry for
`t'.

I think your literal reading is correct though.

*My* beef with the thunk generation scheme (as you know :-) ) was that
we didn't just generate thunks everywhere, in COMDAT, and then allow
implementations to DTRT by generating an overriding strong symbol.
Bizarre SCO linkers aside, I still like that solution best...

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com



More information about the Gcc-patches mailing list