[cxx-abi-dev] Virtual base allocation question

Nathan Sidwell nathan at codesourcery.com
Mon Oct 15 09:53:03 UTC 2001


"Nelson, Clark" wrote:
> 
> Consider the following case:
> 
> struct S { virtual void s(void) {} };
> struct T : virtual public S { virtual void t(void) {} };
> struct W : virtual public S { virtual void w(void) {} };
> struct Y : virtual public T, public W {
>   virtual void x(void) {}
> };

> The question is, what is the offset of S in Y? Y actually contains 2
> sub-objects of type S, one each in sub-objects of type T and W. But
> according to the language rules, S is not an ambiguous base of Y, so
> conversion from Y* to S* is well-formed. Then what's the value of the
> result?
S is at offset 4 within the T sub object. The virtual primary bases are
allocated in inheritance graph order. T is met before W, so T gets
S as a primary base.

hope that helps. BTW, you can use -fdump-class-hierarchy on gcc 3.0 to
output what it thinks the layout should be (if you find errors, please
let me know!)

nathan

-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan at codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan at acm.org



More information about the cxx-abi-dev mailing list