target/3923: [Solaris 8 on Sparc IIe] -O2 option trashes variables
rth@gcc.gnu.org
rth@gcc.gnu.org
Sat Mar 30 13:15:00 GMT 2002
Synopsis: [Solaris 8 on Sparc IIe] -O2 option trashes variables
State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Sat Mar 30 13:15:15 2002
State-Changed-Why:
float fMantissa = input;
fMantissa += 1.0F;
fMantissa -= exponent;
unsigned long &mantissa = * reinterpret_cast<unsigned long *> (&fMantissa);
This is illegal. An object may only be accessed through its
proper type. See section 6.5 paragraph 7 of the ISO C standard;
there is a corresponding verbage in the C++ standard, but I
forget the exact section number.
Use a union instead:
union {
float f;
unsigned long l;
} u;
u.f = input + 1.0f - exponent;
u.l &= ...
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=3923
More information about the Gcc-prs
mailing list