From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11761 invoked by alias); 28 Mar 2004 23:19:59 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 11718 invoked from network); 28 Mar 2004 23:19:58 -0000 Received: from unknown (HELO sv1.lisha.ufsc.br) (150.162.62.1) by sources.redhat.com with SMTP; 28 Mar 2004 23:19:58 -0000 Received: from sv1.lisha.ufsc.br (localhost.localdomain [127.0.0.1]) by sv1.lisha.ufsc.br (8.12.10/8.12.10) with ESMTP id i2SNJvkV003240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 28 Mar 2004 20:19:58 -0300 Received: (from apache@localhost) by sv1.lisha.ufsc.br (8.12.10/8.12.5/Submit) id i2SNJvvR003238; Sun, 28 Mar 2004 20:19:57 -0300 From: Tiago Stein X-Authentication-Warning: sv1.lisha.ufsc.br: apache set sender to tiago@localhost using -f Received: from 200.138.253.131 (SquirrelMail authenticated user tiago) by www.lisha.ufsc.br with HTTP; Sun, 28 Mar 2004 20:19:57 -0300 (BRT) Message-ID: <65184.200.138.253.131.1080515997.squirrel@www.lisha.ufsc.br> Date: Mon, 29 Mar 2004 13:57:00 -0000 Subject: Double abstract class Inheritance concern. To: gcc@gcc.gnu.org User-Agent: SquirrelMail/1.4.0-1 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 X-SW-Source: 2004-03/txt/msg01648.txt.bz2 Hy! I have question concerning inheritance of empty classes. Supose that I have: Class A{ }; Class B: public A{ unsigned int foo1; }; because of C++ constraints on object sizes.. sizeof(A) is 4 (I am in a 32bit PC). In class B, due to the attribute.. this extra size form A is supressed. So sizeof B= 4 too.. Until here everything is OK, but... given: class A{ }; class B :public A{ }; class C: public A{ int g; }; class D: public B, public C { unsigned int foo; }; Why sizeof class D is 12? Should not be 8? Why the extra size from the empty classes is not eliminated this time? Is this due to any rules in the standard? I passed hours looking for it but found nothing that could obligate so. This behavior is causing some real nasty side-effects in our operating system due to memory restrictions in our embedded targets. So, can someone explain me why of this? Maybe I am leaving something wrong pass at my design if there is any rule that dictates this behavior. Thanks for any help.