简体   繁体   English

GCC用-O0和-O2给出不同的数值结果

[英]GCC giving different numerical results with -O0 and -O2

I'm using 4.1.2. 我正在使用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. 有一些丑陋的指针转换(即,d =(double)(*(float *)p),其中p是指向int的指针)我正在努力消除,但还没有运气。
For what it's worth, -O0 is giving the correct answer. 对于它的价值,-O0给出了正确的答案。 Thanks for any help. 谢谢你的帮助。

I'd check for strict aliasing issues, as demonstrated here: http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html 我将检查严格的别名问题,如下所示: 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. 如果你提供了一些证明问题的代码,它对你有帮助,并使我们更容易回答。

Thanks everyone, -fno-strict-aliasing (suggested by several) solved my problem. 谢谢大家,-fno-strict-aliasing(由几个人建议)解决了我的问题。 Thanks for all your help. 感谢你的帮助。
Lesson learned: Always compile with warning flags. 获得的经验:始终使用警告标志进行编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM