The code below (float.c) fills in a float `f' with 1.00000 by accessing it as an array `fp' of two unsigned integers, and storing the appropriate value in each element of the array. The value printed should therefore be 1.00000, and this is what happens when compiling without optimization options. With -O2 and above, the value printed is 2.0000. Qualifying both `f' and `fp' as volatile seems to eliminate the wrong behavior. Release: gcc version 2.96 20000731 Environment: Red Had Linux 7.1, kernel 2.4.2-2 i686 unknown How-To-Repeat: gcc -O3 float.c -o float ; ./float
Fix: Not using optimizations above -O, or adding volatile to f and fp. However, this is not feasible in my application: the error may appear in many places.
State-Changed-From-To: open->closed State-Changed-Why: This code violates ISO C aliasing rules (paragraph 6.5/7). Use a union instead.
Reopening to ...
Mark as a dup of bug 21920. *** This bug has been marked as a duplicate of 21920 ***