Path: utzoo!attcan!uunet!lll-winken!sun-barr!cs.utexas.edu!milano!cadillac!vaughan@mcc.com From: vaughan@mcc.com (Paul Vaughan) Newsgroups: comp.lang.c++ Subject: Re: Multiple inheritance with virtual bases Message-ID: <12342@cadillac.CAD.MCC.COM> Date: 22 Oct 90 15:44:23 GMT References: <1990Oct21.211143.3459@nowhere.uucp> Sender: news@cadillac.CAD.MCC.COM Reply-To: vaughan@mcc.com (Paul Vaughan) Organization: MCC VLSI CAD Program Lines: 42 In-reply-to: sking@nowhere.uucp (Steven King) The discussion between Kazuyuki Hagiwara and Steven King about the sizes of muliply and virtually derived objects is curious indeed. Here is what GNU C++ does, followed by cfront 2.0 (Sun C++). #include struct A { char avar0[1000]; }; struct B : virtual public A { int bvar; }; struct C : virtual public A { int cvar; }; struct D : virtual public B, virtual public C { int dvar; }; main() { cout << "A " << sizeof(A) << " B " << sizeof(B) << " C " << sizeof(C) << " D " << sizeof(D) << "\n"; } bash$ g++ -o trash trash.cc bash$ trash A 1000 B 1008 C 1008 D 1028 <= reasonable bash$ CC -o trash trash.cc CC trash.cc: cc -o /d2/prism/prism/src/sim/src/trash -I/net/sunspot/usr/cadsw/CC/sun4/incl trash.c -L/net/sunspot/usr/cadsw/CC/sun4/ -lC bash$ trash A 1000 B 1008 C 1008 D 2032 <= unreasonable Paul Vaughan, MCC CAD Program | ARPA: vaughan@mcc.com | Phone: [512] 338-3639 Box 200195, Austin, TX 78720 | UUCP: ...!cs.utexas.edu!milano!cadillac!vaughan