From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 104455 invoked by alias); 18 Aug 2015 16:28:42 -0000 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 Received: (qmail 104443 invoked by uid 89); 18 Aug 2015 16:28:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: gate.crashing.org Received: from gate.crashing.org (HELO gate.crashing.org) (63.228.1.57) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 18 Aug 2015 16:28:39 +0000 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id t7IGSaFC006557; Tue, 18 Aug 2015 11:28:36 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id t7IGSZ4c006556; Tue, 18 Aug 2015 11:28:35 -0500 Date: Tue, 18 Aug 2015 16:28:00 -0000 From: Segher Boessenkool To: john smith Cc: gcc-help@gcc.gnu.org Subject: Re: Where does C standard mention alignment requirements as written in gcc manual? Message-ID: <20150818162835.GD30482@gate.crashing.org> References: <20150818155042.GC30482@gate.crashing.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-IsSubscribed: yes X-SW-Source: 2015-08/txt/msg00081.txt.bz2 On Tue, Aug 18, 2015 at 05:57:36PM +0200, john smith wrote: > >> "Note that the alignment of any given struct or union type is required > >> by the ISO C standard to be at least a perfect multiple of the lowest > >> common multiple of the alignments of all of the members of the struct > >> or union in question." > >> > >> Where exactly is this requirement mentioned in C standard? I was > >> looking for it in both C99 and C11 drafts and couldn't find it. > > > > C99 6.7.2.1/12 ? > > It just says that "Each non-bit-field member of a structure or union > object is aligned in an implementation-defined manner appropriate to > its type.". It doesn't require an overall alignment of the structure > to be "at least a perfect multiple of the lowest common multiple of > the alignments of all of the members of the struct". If the alignment of any member of the struct is A, the alignment of the struct has to be a multiple of A (by the above, and the definition of alignment). Now consider all members together, and you get what the GCC manual says. Segher