GCC编译选项--"-fno-strict-aliasing"
来源:互联网 发布:goeasy实现java推送 编辑:程序博客网 时间:2024/06/05 19:18
文中的编码方法绝对要禁止用在项目中, 最近用开源的代码时碰到过需要这个选项的警告
这两天编译别的组的代码。编译器是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 refered there after 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".
0 0
- GCC编译选项--"-fno-strict-aliasing"
- GCC编译选项--"-fno-strict-aliasing"
- 【GCC】gcc编译参数之-fno-strict-aliasing
- MySQL编译选项 -fno-strict-aliasing随手记
- GCC编译参数strict aliasing详解
- GCC strict aliasing
- Gcc编译选项-fno-builtin -fno-builtin-function
- GCC的-fno-builtin选项
- strict aliasing
- gcc -fomit-frame-pointer选项,-fno-dwarf2-cfi-asm 选项
- 善用"Assume No Aliasing"编译选项
- strict aliasing [转载]
- 玩strict aliasing [转载]
- Strict aliasing rule
- 玩strict aliasing
- Understanding Strict Aliasing
- 编译器的strict-aliasing
- does break strict-aliasing rules
- .net 将session存入数据库
- maven生命周期
- 数据结构实验之栈八:栈的基本操作 简单方法
- 在Android和iOS中读取静态图像
- 跳房子
- GCC编译选项--"-fno-strict-aliasing"
- Linux菜鸟学习之网络浅入
- 杭电ACM2005题(第几天?)------Java语言
- java 集合框架简介
- 24点游戏
- C#中internal关键字的作用
- makefile编写小结:多目录,单Makefile
- maven pom.xml详解
- HDU 2063 过山车 【匈牙利算法,二分图最大匹配】