From owner-freebsd-current@FreeBSD.ORG Sat Feb 14 16:19:32 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C90F916A4CE for ; Sat, 14 Feb 2004 16:19:32 -0800 (PST) Received: from mailout1.pacific.net.au (mailout1.pacific.net.au [61.8.0.84]) by mx1.FreeBSD.org (Postfix) with ESMTP id 507AB43D1F for ; Sat, 14 Feb 2004 16:19:32 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87])i1F0JULE004217; Sun, 15 Feb 2004 11:19:30 +1100 Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) i1F0JSch005619; Sun, 15 Feb 2004 11:19:29 +1100 Date: Sun, 15 Feb 2004 11:19:28 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Poul-Henning Kamp In-Reply-To: <8832.1076796994@critter.freebsd.dk> Message-ID: <20040215105358.Y6635@gamplex.bde.org> References: <8832.1076796994@critter.freebsd.dk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: current@freebsd.org Subject: Re: GCC bug ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2004 00:19:32 -0000 On Sat, 14 Feb 2004, Poul-Henning Kamp wrote: > This seems wrong to me, GCC should warn about the double initialization. > > critter phk> cat a.c > > struct foo { > int bar; > int barf; > }; > > struct foo myfoo = { > .bar = 1, > .bar = 2, > }; > critter phk> cc -Wall -c a.c > critter phk> This seems to be a feature. From n869.txt: %%% [#19] The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject; all subobjects that are not initialized explicitly shall be initialized implicitly the same as objects that have static storage duration. %%% Initialization of a previously inititialized subobject should be allowed when the previous initialization was the default. Perhaps it was too hard to specify a non-overriding behaviour for later initializations in special cases. Yes, the following should work too: %%% struct foo { int f_bar; int f_barf; }; struct foobar { struct foo fb_bar; int fb_barf; }; struct foobar myfoobar = { .fb_bar = { 1 }, .fb_bar.f_barf = 2, }; %%% ".fb_bar.f_barf" is initialized twice, first with the default part of an expilicit initialization. I could have avoided the first initialization by initializing only .fb_bar.f_bar, but chose not to, to give an example. More complicated examples might not have a choice in practice. Also, the opposite order might be needed: struct foobar myfoobar = { .fb_bar.f_barf = 2, .fb_bar = { 1 }, }; to suit complexities not shown in this example. The above just clobbers the first initialization of ".fb_bar.f_barf". In a more complicated example, clobbering some initializations might be hard to avoid. Then further initializations would be needed to unclobber them. Bruce