public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58303] New: C99 union initializers new union members clobber earlier data
@ 2013-09-03 4:05 darrenrjenkins at gmail dot com
2013-09-03 6:11 ` [Bug c/58303] " jakub at gcc dot gnu.org
2013-09-03 6:27 ` mpolacek at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: darrenrjenkins at gmail dot com @ 2013-09-03 4:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58303
Bug ID: 58303
Summary: C99 union initializers new union members clobber
earlier data
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: darrenrjenkins at gmail dot com
If using C99 initializers on a union, and using different union members.
The later members seem to clobber the previous members data.
I haven't looked at the standards with respect to this, but it seems wrong.
#include <stdio.h>
typedef struct
{
int a;
int b;
} a_t;
typedef struct
{
int c;
int d;
} b_t;
typedef union
{
a_t a;
b_t b;
} c_t;
void main( int argc, char *argv[] )
{
c_t var = { .a.a = 4, .b.d = 7 };
printf( ".a.a = %d .b.d = %d\n", var.a.a, var.b.d );
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/58303] C99 union initializers new union members clobber earlier data
2013-09-03 4:05 [Bug c/58303] New: C99 union initializers new union members clobber earlier data darrenrjenkins at gmail dot com
@ 2013-09-03 6:11 ` jakub at gcc dot gnu.org
2013-09-03 6:27 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-09-03 6:11 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58303
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
In C99, only one union member may be active at a time, assignment to one of
union members invalidates all the others. So I don't see anything wrong on
this.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/58303] C99 union initializers new union members clobber earlier data
2013-09-03 4:05 [Bug c/58303] New: C99 union initializers new union members clobber earlier data darrenrjenkins at gmail dot com
2013-09-03 6:11 ` [Bug c/58303] " jakub at gcc dot gnu.org
@ 2013-09-03 6:27 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2013-09-03 6:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58303
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |mpolacek at gcc dot gnu.org
Resolution|--- |INVALID
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
An initializer for an union is a single value. In C89, only the first member
of a union can be initialized; in C99/C11 you can use the designated
initializers to specify which member to initialize, but still only a single
member of an union can be initialized.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-09-03 6:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-03 4:05 [Bug c/58303] New: C99 union initializers new union members clobber earlier data darrenrjenkins at gmail dot com
2013-09-03 6:11 ` [Bug c/58303] " jakub at gcc dot gnu.org
2013-09-03 6:27 ` mpolacek at gcc dot gnu.org
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).