views:

204

answers:

2

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.

+7  A: 

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
The post http://stackoverflow.com/questions/83962/do-i-have-a-gcc-optimization-bug-or-a-c-code-problem shows a similar problen
an0nym0usc0ward
Compiling with Wall (suggested above) did it. The bad line is *(p1 + dcb.ntrc_hdr + r*NTW + t) = * (int *)
+3  A: 

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

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