GCC编译选项--"-fno-strict-aliasing"

GCC编译选项--"-fno-strict-aliasing"

  (2009-08-09 14:31:45)
标签: 

杂谈

分类: 计算机与 Internet
    这两天编译别的组的代码。编译器是GCC4.1.2,发现使用优化选项O2以上代码执行的结果和使用O1(或不使用优化选项)不一样,使用O1编译出来的代码执行结果是正确的。上网搜索了一下,发现了原因。
    代码中有如下语句:
          float f = j;
          unsigned int* p = (unsigned int*)(&f);
    上述代码的第二句有强制类型转化,是出现问题的原因。原因及解决方法如下,是英文的:
 
    If optimization level is >= 2 in gcc-4.1, strict-aliasing is used, and this could cause probelms when a pointer is referencing to a different type of object and the object is referedthereafter by using this pointer. That is the case in this example. So you should force the compiler to not use strict-aliasing by a argument "-fno-strict-aliasing" if you want to use "-O2" or "-O3".
 
    看来以后得多学习一下GCC编译器的选项的意义了。
posted on 2012-11-21 14:22 小小程序员001 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/musicfans/archive/2012/11/21/2819287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值