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.
Asked
Active
Viewed 539 times
4
-
3could you provide a minimum (non) working example ? – Gyom Jul 02 '09 at 02:44
-
Are you compiling with -Wall and -Wextra? – Adam Rosenfield Jul 02 '09 at 02:50
-
Sorry, I'm working on it. Heavy going. – Jul 02 '09 at 02:51
-
http://delta.tigris.org is an excellent tool for automated minimization of a test case. – ephemient Jul 02 '09 at 18:27
-
The other thing that would lead to slightly different results with optimization is that the x86 FPU has more precision than specified, so unoptimized code that forces values to be written into the stack frame between operations will truncate the lower bits. – Simon Richter May 11 '11 at 10:45
2 Answers
7
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.

Justicle
- 14,761
- 17
- 70
- 94
-
The post http://stackoverflow.com/questions/83962/do-i-have-a-gcc-optimization-bug-or-a-c-code-problem shows a similar problen – an0nym0usc0ward Jul 02 '09 at 02:54
-
Compiling with Wall (suggested above) did it. The bad line is *(p1 + dcb.ntrc_hdr + r*NTW + t) = * (int *) &ftmp; – Jul 02 '09 at 02:55
3
Thanks everyone, -fno-strict-aliasing (suggested by several) solved my problem. Thanks for all your help.
Lesson learned: Always compile with warning flags.
-
1Stack Overflow is not a forum. Answers may be reordered for many reasons, such as votes and edits, and thus should not be used to reply to other answers. Please leave comments or edit the question instead. Also, if your issue has been resolved due to an answer, please mark it as accepted (click the green check mark under the vote counter). Don't forget to vote up helpful responses! – ephemient Jul 02 '09 at 18:26