From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4330 invoked by alias); 23 Apr 2003 19:13:22 -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 4283 invoked from network); 23 Apr 2003 19:13:21 -0000 Received: from unknown (HELO uniton.integrable-solutions.net) (62.212.99.186) by sources.redhat.com with SMTP; 23 Apr 2003 19:13:21 -0000 Received: from uniton.integrable-solutions.net (localhost [127.0.0.1]) by uniton.integrable-solutions.net (8.12.3/8.12.3/SuSE Linux 0.6) with ESMTP id h3NJ7aH2027028; Wed, 23 Apr 2003 21:07:36 +0200 Received: (from gdr@localhost) by uniton.integrable-solutions.net (8.12.3/8.12.3/Submit) id h3NJ7ZYJ027027; Wed, 23 Apr 2003 21:07:35 +0200 X-Authentication-Warning: uniton.integrable-solutions.net: gdr set sender to gdr@integrable-solutions.net using -f To: tromey@redhat.com Cc: Jason Merrill , Jamie Lokier , Andrew Haley , gcc@gcc.gnu.org Subject: Re: On alignment 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> From: Gabriel Dos Reis In-Reply-To: <87lly1f5ir.fsf@fleche.redhat.com> Organization: Integrable Solutions Date: Wed, 23 Apr 2003 19:33:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2003-04/txt/msg01175.txt.bz2 Tom Tromey writes: | >>>>> "Jason" == Jason Merrill writes: | | [ about struct foo { double x; } ] | | Tom> I'd like to find the most future-proof way to do this. In the above, | Tom> is __alignof__(foo::x) the best way? I'm only concerned with | Tom> alignment of fields. | | Jason> It is since my recent patch to do all alignment calculation for | Jason> fields in layout_decl. | | I can't do this. | | struct aligner { double field; }; | | int compute () { return __alignof__ (aligner::field); } | | fleche. gcc -c y.cc | y.cc: In function `int compute()': | y.cc:1: error: invalid use of non-static data member `aligner::field' | y.cc:3: error: from this location The following does the job: template struct object_alignment { struct helper { T& datum; helper(); }; static helper instance; enum { value = __alignof__ (instance.datum) }; }; To be used as object_alignment::value. | I can use __alignof__(aligner), but my concern is that eventually this | will yield "8" instead of "4" on x86. With the above, the following #include int main() { std::cout << object_alignment::value << std::endl; } outputs "8" on an i686-pc-linux-gnu. Enjoy ;-) -- Gaby