From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19815 invoked by alias); 29 Mar 2004 07:57:29 -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 19808 invoked from network); 29 Mar 2004 07:57:27 -0000 Received: from unknown (HELO garibaldi.home) (82.32.50.9) by sources.redhat.com with SMTP; 29 Mar 2004 07:57:27 -0000 Received: from codesourcery.com (localhost.localdomain [127.0.0.1]) by garibaldi.home (8.12.8/8.12.8) with ESMTP id i2T7vIMo008527; Mon, 29 Mar 2004 08:57:19 +0100 Message-ID: <4067D6DD.1060607@codesourcery.com> Date: Mon, 29 Mar 2004 17:16:00 -0000 From: Nathan Sidwell Organization: Codesourcery LLC User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 MIME-Version: 1.0 To: Chris Lattner CC: Tiago Stein , gcc@gcc.gnu.org Subject: Re: Double abstract class Inheritance concern. References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-03/txt/msg01654.txt.bz2 Chris Lattner wrote: > Tiago Stein wrote: > >>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? > > > I believe the reason is that the ABI does not permit multiple different > instances of A to be located at the same address, even if they have zero > size. If the size of the structure was 8, all of "A", "B", and "A" would > have offset zero. > > I'm not sure WHY this is required, but this is the reason it happens at > least. A declaration of "A X[100];" allocates 100 bytes as > a result of the same rule. It is a C++ language requirement that no two logically distinct objects of the same type have the same address. BEWARE. GNU C has an empty struct extension to C, that does not obey the same rules. nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk