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

发布于 2024-07-26 03:25:41 字数 154 浏览 3 评论 0原文

我用的是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

累赘 2024-08-02 03:25:41

我会检查严格的别名问题,如下所示:
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.

小巷里的女流氓 2024-08-02 03:25:41

谢谢大家,-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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文