This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
Re: target/3923: [Solaris 8 on Sparc IIe] -O2 option trashes variables
- From: rth at gcc dot gnu dot org
- To: benoit dot maricau at etca dot alcatel dot be, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, thierry dot van_humbeeck at etca dot alcatel dot be
- Date: 30 Mar 2002 21:15:16 -0000
- Subject: Re: target/3923: [Solaris 8 on Sparc IIe] -O2 option trashes variables
- Reply-to: rth at gcc dot gnu dot org, benoit dot maricau at etca dot alcatel dot be, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org, thierry dot van_humbeeck at etca dot alcatel dot be, gcc-gnats at gcc dot gnu dot org
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