Article View: gnu.gcc.bug
Article #735union initializers with elided braces
From: Paul Eggert
Date: Thu, 19 Oct 1989 19:34
Date: Thu, 19 Oct 1989 19:34
40 lines
2134 bytes
2134 bytes
GCC should process initializers with elided braces independently of whether
they initialize unions or structures. For example, the following program
should initialize x and y to identical values:
union u {
int a[2];
};
union u x = { { 1, 2 } };
union u y = { 1, 2 };
Unfortunately, GCC complains about the second initialization above on a
Sparcstation-1 under SunOS 4.0.3c:
% gcc -v t.c
gcc version 1.36
/local/lib/gcc-cpp -v -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ t.c /usr/tmp/cca04523.cpp
GNU CPP version 1.36
/local/lib/gcc-cc1 /usr/tmp/cca04523.cpp -quiet -dumpbase t.c -version -o /usr/tmp/cca04523.s
GNU C version 1.36 (sparc) compiled by GNU C version 1.36.
default target switches: -mfpu -mepilogue
t.c:6: union initializer requires one element
GCC does not complain if 'union' is uniformly changed to 'struct'.
Here's why GCC's behavior should change. The proposed ANSI standard says
(section 3.5.7, page 73, lines 21-27 of the December 7, 1988 draft):
If the aggregate contains members that are aggregates or unions, or if
the first member of a union is an aggregate or union,... [and] if the
initializer of a subaggregate or contained union [does not begin]...
with a left brace,... only enough initializers from the list are taken
to account for the members of the subaggregate or the first member of
the contained union;...
That is, with respect to eliding braces, the standard uses the same language
for initializing unions as it does for initializing other aggregates including
structures. In particular, braces can be elided for a union with just one
member in the same way that they can be elided for a structure with just one
member.
Technical Details
Message-ID:
<8910191934.AA04570@rise.twinsun.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!iuvax!cica!tut.cis.ohio-state.edu!twinsun.com!eggertShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!iuvax!cica!tut.cis.ohio-state.edu!twinsun.com!eggert From: eggert@twinsun.com (Paul Eggert) Newsgroups: gnu.gcc.bug Subject: union initializers with elided braces Message-ID: <8910191934.AA04570@rise.twinsun.com> Date: 19 Oct 89 19:34:15 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 40