Path: utzoo!attcan!uunet!microsoft!dans From: dans@microsoft.UUCP (Dan SPALDING) Newsgroups: comp.lang.c++ Subject: Re: Multiple inheritance with virtual bases Message-ID: <58572@microsoft.UUCP> Date: 27 Oct 90 20:29:17 GMT References: <1990Oct21.211143.3459@nowhere.uucp> <488@taumet.com> Reply-To: dans@microsoft.UUCP (Dan SPALDING) Organization: Microsoft Corp., Redmond WA Lines: 127 In article <488@taumet.com> steve@taumet.com (Stephen Clamage) writes: >sking@nowhere.uucp (Steven King) writes: > >|In article |HAGIWARA.90Oct18105013@rd14.zuken.co.jp> hagiwara@zuken.co.jp (Kazuyuki Hagiwara) writes: > >This is not correct. Exactly one instance of a virtual base class exists >in an object by definition. Class A is declared to be virtual in all uses >of it, so it is an error for there to be more than one copy. Let us hope >that the error in this case is in the allocation, and that only one copy >is ever referred to by generated code. >-- > >Steve Clamage, TauMetric Corp, steve@taumet.com while that is technically true, cfront generates structure defn's that are not in any way optimal. The space for both the A part of B and C are in B and C, and the class D includes both of these structures and a pointer to the shared A (which is one of the ones in B or C). So, from the user's point of view, there is only one A, but the space for two of them is consumed. Not very neat is it? here is an example of mi.cxx and it's resultant mi.c from Glock 2.0: mi.cxx: class A { char _rgb[1000]; }; class B : public virtual A { int _w; }; class C : public virtual A { int _w; }; class D : public virtual B, public virtual C { int _w; }; main () { D * pd; }; mi.c: #line 1 "mi.cxx" /* << cfxx :- 2.0 Msoft a >> */ /* < mi.cxx > */ static void __cvp30_support(void) {} void * __vec_new ( void * , int , int , void * ) #line 1 ; #line 1 void __vec_delete ( void * , int , int , void * , int #line 1 , int ) ; typedef int (*__vptp)(); struct __mptr {short d; short i; __vptp f; }; static void _cdecl _STI(); static void _cdecl _STD(); #line 1 struct A; struct A { /* sizeof A == 1000 */ char _rgb__1A [ 1000] ; }; struct B; struct B { /* sizeof B == 1006 */ int _w__1B ; struct A * PA; struct A OA; }; #line 1 extern void * __nw__FUi ( unsigned int ) ; struct C; #line 7 struct C { /* sizeof C == 1006 */ int _w__1C ; struct A * PA; struct A OA; }; struct D; #line 9 #line 6 #line 10 struct D { /* sizeof D == 2026 */ int _w__1D ; struct C * PC; struct B * PB; struct A * PA; struct C OC; struct B OB; }; #line 14 int main ( void ) { { struct D * pd ; } } #line 16 /* the end */ ------------------------------------------------------------------------ dan spalding -- microsoft systems/languages -- microsoft!dans "there has not been a word invented that would convey my indifference to that remark." - paraphrase from hawkeye pierce ------------------------------------------------------------------------