GCC 使用 -O0 和 -O2 给出不同的数值结果
我用的是4.1.2。 有人知道我的代码中最好看的地方吗? 常见原因的经验? 我正在努力消除一些丑陋的指针转换(即 d = (double) (* (float *) p),其中 p 是指向 int 的指针),但还没有运气。
无论如何,-O0 给出了正确的答案。 谢谢你的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会检查严格的别名问题,如下所示:
http://www.cellperformance.com/mike_acton/2006/06/understand_strict_aliasing。 html
在不知道你的代码到底做了什么的情况下,提到“丑陋的指针转换”让我怀疑别名问题。
如果您提供一些演示该问题的代码,这将对您有所帮助,并使我们更容易回答。
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.
谢谢大家,-fno-strict-aliasing(几个人建议)解决了我的问题。 感谢您的帮助。
经验教训:始终使用警告标志进行编译。
Thanks everyone, -fno-strict-aliasing (suggested by several) solved my problem. Thanks for all your help.
Lesson learned: Always compile with warning flags.