4

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.

5
  • 3
    could you provide a minimum (non) working example ? Commented Jul 2, 2009 at 2:44
  • Are you compiling with -Wall and -Wextra? Commented Jul 2, 2009 at 2:50
  • Sorry, I'm working on it. Heavy going. Commented Jul 2, 2009 at 2:51
  • delta.tigris.org is an excellent tool for automated minimization of a test case. Commented Jul 2, 2009 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. Commented May 11, 2011 at 10:45

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The post stackoverflow.com/questions/83962/… shows a similar problen
Compiling with Wall (suggested above) did it. The bad line is (p1 + dcb.ntrc_hdr + rNTW + t) = * (int *) &ftmp;
3

Thanks everyone, -fno-strict-aliasing (suggested by several) solved my problem. Thanks for all your help.
Lesson learned: Always compile with warning flags.

1 Comment

Stack 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!