GCC giving different numerical results with -O0 and -O2
c, gcc, numerical, optimization
Solution
I'd check for strict aliasing issues, as demonstrated here: http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html
Without knowing exactly what your code does, the mention of "ugly pointer casts" make me suspect aliasing problems.
It would be helpful for you, and make it easier for us to answer, if you provided some code that demonstrated the issue.
Problem
I'm using 4.1.2. Does anyone have any ideas of the best places in my code to look? Experience with common causes? There are some ugly pointer casts (ie, d = (double) (* (float *) p), where p is pointer-to-int) that I'm working on eliminating, but no luck yet. For what it's worth, -O0 is giving the correct answer. Thanks for any help.