public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@dcc.unicamp.br> To: Aurel Balmosan <ab@orga.com> Cc: egcs-bugs <egcs-bugs@cygnus.com> Subject: Re: Initialising an union Date: Thu, 20 Aug 1998 08:15:00 -0000 [thread overview] Message-ID: <oru337iw8y.fsf@iguacu.dcc.unicamp.br> (raw) In-Reply-To: <35DBD533.721DB13F@orga.com> Aurel Balmosan <ab@orga.com> writes: > Alexandre Oliva wrote: >> Does it apply to local non-static variables? I'm pretty sure this is >> true for variables in static storage, but how about local ones? >> Unfortunately, I don't have access to the ANSI-C Standard :-( [snip] > This make clear that auto and register structs/unions/vektors > can be initialised. That was not my question. I asked whether the standard explicitly stated that uninitialized members of an automatic union would be implicitly zero-initialized. A summary of the related posts to the list follows: 1) automatic unions can be explicitly initialized 2) if a initializer-list contains less elements than the initialized object, the remaining elements are zero-initialized 3) when a union is explicitly initialized, the initializer-list will be used to initialize the first element of the union so, given the following code snippet: union t { int i; char c[sizeof(int)+1]; }; void foo() { union t x = { 0 }; assert(c[sizeof(int)]==0); } Given only the three statements listed above, the assertion *can* fail, because the second type of the union (c) is *not* initialized, only the first one (i) is. Thus, it needs not be zero initialized, based on the claims above. As I have stated earlier, I don't have a copy of the C Standard, and I'd be happy to find out that the Standard does specify that union initialization must be performed as if the whole union were zero-initialized before explicit initialization takes place. It's just that I haven't read (or understood :-) any claim that supports this interpretation, and it doesn't look much like C to me :-) -- Alexandre Oliva mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org http://www.dcc.unicamp.br/~oliva Universidade Estadual de Campinas, SP, Brasil
next prev parent reply other threads:[~1998-08-20 8:15 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 1998-08-18 0:39 Aurel Balmosan 1998-08-18 18:14 ` Alexandre Oliva 1998-08-19 2:44 ` Aurel Balmosan 1998-08-19 14:51 ` Alexandre Oliva 1998-08-20 2:41 ` Aurel Balmosan 1998-08-20 8:15 ` Alexandre Oliva [this message] -- strict thread matches above, loose matches on Subject: below -- 1998-08-17 7:51 Aurel Balmosan 1998-08-18 11:46 ` Jeroen Dobbelaere 1998-08-19 4:40 ` Aurel Balmosan 1998-08-19 10:03 ` Jeroen Dobbelaere
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=oru337iw8y.fsf@iguacu.dcc.unicamp.br \ --to=oliva@dcc.unicamp.br \ --cc=ab@orga.com \ --cc=egcs-bugs@cygnus.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).