gcc compiler bug
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Thu Jun 1 22:46:00 GMT 2000
> This certainly looks like a bug:
> - it works differently under two versions of gcc
> - it does not appear on other platforms where gcc compilers
> operate
Thanks for your bug report. This is not a bug in the compiler, but in
your code; it has unspecified behaviour. First, you write
X.i[0]=0xFFFFFFFF;
X.i[1]=0xFFF7FFFF;
Y.d=X.x;
In ISO C99, 6.2.6.1/7 says
# When a value is stored in a member of an object of union type, the
# bytes of the object representation that do not correspond to that
# member but do correspond to other members take unspecified values,
# but the value of the union object shall not thereby become a trap
# representation.
So clearly Y.d has an unspecified value after the assignment. Even if
you assume that it has the binary representation given above (which
you cannot assume in standard C), then we have 6.2.6.1/1
# The representations of all types are unspecified except as stated in
# this subclause.
Since that subclause imposes no further requirements on the
representation of double values, you cannot expect anything on this
representation. For example, a conforming implementation may chose to
incorporate the current time into the representation of a double
value, if it choses to.
Therefore, a program relying on these things is broken.
Regards,
Martin
More information about the Gcc-bugs
mailing list