From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4600 invoked by alias); 26 May 2011 12:05:25 -0000 Received: (qmail 4585 invoked by uid 22791); 26 May 2011 12:05:24 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-px0-f172.google.com (HELO mail-px0-f172.google.com) (209.85.212.172) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 26 May 2011 12:04:56 +0000 Received: by pxi6 with SMTP id 6so427651pxi.17 for ; Thu, 26 May 2011 05:04:55 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.127.20 with SMTP id z20mr104221wfc.305.1306411495175; Thu, 26 May 2011 05:04:55 -0700 (PDT) Received: by 10.142.69.21 with HTTP; Thu, 26 May 2011 05:04:55 -0700 (PDT) In-Reply-To: <4DDE393F.4030103@gmail.com> References: <4DDE393F.4030103@gmail.com> Date: Thu, 26 May 2011 18:02:00 -0000 Message-ID: Subject: Re: Member offsets in multiple inheritance From: Jonathan Wakely To: pieniek Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg00394.txt.bz2 On 26 May 2011 12:27, pieniek wrote: > Hello, > > I have always though, that given a pointer to an object, members are at > (this) + (member-offset). But this cannot be true for multiple inheritanc= e, > no? > > Example: > > struct A { > =A0 int x,y; > } > > struct B { > =A0 int a, b, c; > } > > struct C : public A, public B {} > > int func (B* b, B* actuallyCinstance) { > =A0 =A0return b->b + actuallyCinstance->b; > } actuallyCinstance points to the B sub-object of a C instance, so the offset to B::b is the same for both dereferences.