From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8222 invoked by alias); 5 May 2003 14:56:33 -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 8128 invoked from network); 5 May 2003 14:56:31 -0000 Received: from unknown (HELO lacrosse.corp.redhat.com) (66.187.233.200) by sources.redhat.com with SMTP; 5 May 2003 14:56:31 -0000 Received: from prospero.boston.redhat.com (sebastian-int.corp.redhat.com [172.16.52.221]) by lacrosse.corp.redhat.com (8.11.6/8.9.3) with ESMTP id h45EuUH01697; Mon, 5 May 2003 10:56:30 -0400 Received: by prospero.boston.redhat.com (Postfix, from userid 4046) id 62815F8D5F; Mon, 5 May 2003 10:55:03 -0400 (EDT) To: Gabriel Dos Reis Cc: tromey@redhat.com, Andrew Haley , Jamie Lokier , gcc@gcc.gnu.org Subject: Re: On alignment From: Jason Merrill In-Reply-To: (Gabriel Dos Reis's message of "02 May 2003 15:07:54 +0200") References: <200303251122.13693.kevin.hendricks@sympatico.ca> <200303251344.59988.kevin.hendricks@sympatico.ca> <16037.6826.35777.756256@cuddles.redhat.com> <20030423124944.GA24593@mail.jlokier.co.uk> <87wuhlgq5l.fsf@fleche.redhat.com> <87lly1f5ir.fsf@fleche.redhat.com> <87sms9dmuy.fsf@fleche.redhat.com> <16039.44856.826662.680167@cuddles.redhat.com> <87znm6utca.fsf@fleche.redhat.com> Date: Mon, 05 May 2003 14:56:00 -0000 Message-ID: User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-05/txt/msg00389.txt.bz2 On 02 May 2003 15:07:54 +0200, Gabriel Dos Reis wrote: > Tom Tromey writes: > > [...] > > | What will eventually go wrong with what we have now? > | > | template > | struct aligner > | { > | T field; > | }; > | > | #define ALIGNOF(TYPE) (__alignof__ (((aligner *) 0)->field)) > > This, as I understand it from my previous attempt, won't give you the > right answer (for double, it would give 8 instead of 4). It will give you the right answer on the trunk (and I just checked in a patch so it will give you the right answer in 3.3 as well). > What is wrong with the following code I posted earlier? > > template > struct alignment { > > struct helper { > T datum; > helper(); > }; > > static helper instance; > > enum { value = __alignof__ (instance) }; > }; The alignment of a non-field instance of a class can be greater that the alignment of the class itself. Just saying __alignof (helper) should work, though I'm not sure it's guaranteed to work. Also, why do you give helper a constructor? Tom's example above is directly asking the question they want an answer to; as long as it works, that's the best way to do it, and it does work now. Jason