[Bug c/59520] a possible inconsistency in error diagnostics with "-pedantic -std=c99"
jakub at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Dec 20 09:35:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59520
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> Let me raise another question that is unrelated, but perhaps you folks, in
> particular Joseph, could help add some clarify as I have been baffled by a
> couple of examples.
>
> In particular, are the following well-defined according the standard or they
> have undefined behavior?
AFAIK neither is well-defined according to base standards, in C (and C++?) the
only valid accesses to union are to the last stored field, but it is accepted
as GNU extension.
> Ex 2
> ====
>
> int printf (const char *, ...);
>
> struct S0
> {
> char f0;
> int f1;
> };
>
> union
> {
> int f0;
> struct S0 f1;
> } d;
>
> int
> main ()
> {
> struct S0 g = {0,0};
> d.f1 = g;
> printf ("%d\n", d.f0);
This is of course undefined behavior even with the GNU extensions, padding bits
in g are undefined and you are then accessing them. It is the same thing
as if you did struct S0 g = {0,0}; memcpy (&d.f0, &g, sizeof (int)); printf
("%d\n", d.f0);
More information about the Gcc-bugs
mailing list