From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1959 invoked by alias); 18 Mar 2003 15:26:55 -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 1758 invoked from network); 18 Mar 2003 15:26:52 -0000 Received: from unknown (HELO cuddles.cambridge.redhat.com) (81.96.64.123) by sources.redhat.com with SMTP; 18 Mar 2003 15:26:52 -0000 Received: (from aph@localhost) by cuddles.cambridge.redhat.com (8.11.6/8.11.0) id h2IFQkA18575; Tue, 18 Mar 2003 15:26:46 GMT From: Andrew Haley MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15991.15030.380667.367246@cuddles.cambridge.redhat.com> Date: Tue, 18 Mar 2003 16:16:00 -0000 To: gcc@gcc.gnu.org Subject: g++: __attribute__ ((aligned)) weirdness X-SW-Source: 2003-03/txt/msg01199.txt.bz2 The doc says The `aligned' attribute can only increase the alignment; but you can decrease it by specifying `packed' as well. See below. but this doesn't seem to be true. For example, on x86 g++ you have a non-POD class and a subclass: ----------------------------------------------------------------------------- class Boof { int arse () { return 25; } void *prickle; }; class foo : Boof { public: long long i; }; ----------------------------------------------------------------------------- then try: ----------------------------------------------------------------------------- foo f; fprintf(stderr, "offset: %d\n", (char *)&f.i - (char *)&f); ----------------------------------------------------------------------------- offset: 4 Fair enough, this long long is probably 4-aligned. Now do this: ----------------------------------------------------------------------------- class bar : Boof { public: long long __attribute__((aligned(4))) i; }; bar b; fprintf(stderr, "offset: %d\n", (char *)&b.i - (char *)&b); ----------------------------------------------------------------------------- offset: 8 So you have a field at offset 4. You ask for it to be 4-aligned, and it jumps to offset 8. What is going on? Andrew.