Virtual base allocation (was: Typo ...)

Jim Dehnert dehnert at sgi.com
Mon Apr 3 23:48:09 UTC 2000


I believe this is not correct.  We ultimately decided not to make
separate allocation of primary bases dependent on whether they
occurred earlier than their derived class in the hierarchy.  Is
this what others recall?  (That's what the document says now.)

(I did add the example, suitably modified.)

Jim

Mark Mitchell wrote:
> I think it would be useful to note the following example near that
> paragraph.  (The C++ standard contains examples intermixed with the
> rules, and it makes it much easier to read.)
> 
>   Consider:
> 
>     struct R { virtual void r (); };
>     struct S { virtual void s (); };
>     struct T : virtual public S { virtual void t (); };
>     struct U : public R, virtual public T { virtual void u (); };
> 
>   R is the primary base class for U since it is the first direct
>   non-virtual dynamic base.  Then, since an inheritance-order walk of
>   U is { U, R, T, S } the T base is allocated next.  Since S is a
>   primary base of T, there is no need to allocate it separately.
>   However, given:
> 
>     struct V : public R, virtual public S, virtual public T {
>       virtual void v ();
>     };
> 
>   the inheritance-order walk of V is { V, R, S, T } so S is allocated
>   first as a virtual base.  Then, T is allocated separately.  Thus
>   sizeof (V) > sizeof (U).
> 
> --
> Mark Mitchell                   mark at codesourcery.com
> CodeSourcery, LLC               http://www.codesourcery.com




More information about the cxx-abi-dev mailing list