【GCC】gcc编译参数之-fno-strict-aliasing
来源:互联网 发布:辽宁11选5遗漏数据 编辑:程序博客网 时间:2024/06/08 19:39
### Date: 2017/5/18
### Author: SoaringLee
先来看下gcc对strict aliasing的解释:
Allows the compiler to assume the strictest aliasing rules applicable to the language being compiled. For C (and C++), this activates optimizations based on the type of expressions. In particular, an object of one type is assumed never to reside at the same address as an object of a different type, unless the types are almost the same. For example, an unsigned int can alias an int, but not avoid* or a double. A character type may alias any other type.
要确保不违反这个规则,那么确实需要让不同指针指向同一个内存位置怎么办?对于已有的代码,违反的地方非常多,那么可以加gcc的-fno-strict-aliasing参数。其实在开启优化选项-O2和-O3的情况下,gcc会自动采用strict
aliasing进行编译器的优化。为了允许不同指针指向同一个内存位置,需要加gcc的编译选项: CFLAGS+=-fno-strict-aliasing。
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 thereafter 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".
错误实例:
在存在强制类型转换的情况下,采用-O1和采用-O2或-O3产生的运行结果是不同的。
float f = j; unsigned int* p = (unsigned int*)(&f);
阅读全文
0 0
- 【GCC】gcc编译参数之-fno-strict-aliasing
- GCC编译选项--"-fno-strict-aliasing"
- GCC编译选项--"-fno-strict-aliasing"
- GCC编译参数strict aliasing详解
- GCC strict aliasing
- gcc 参数 -fno-builtin
- MySQL编译选项 -fno-strict-aliasing随手记
- Gcc编译选项-fno-builtin -fno-builtin-function
- GCC -fno-omit-frame-pointer
- GCC的-fno-builtin选项
- gcc编译参数之m32 m64
- gcc最佳编译参数
- gcc最佳编译参数
- 常见gcc编译参数
- gcc编译参数
- 问答:gcc编译参数
- gcc编译参数
- GCC编译参数描述
- Maven中央仓库信息速查
- 【编程题】最长公共连续子串
- 通信系统仿真速成第2天:QPSK调制与解调(实验)
- 相似度计算的三种方式
- org.framework can't be resolved
- 【GCC】gcc编译参数之-fno-strict-aliasing
- 头像滑动,中间放大并带点击选中效果
- scikit-learn 交叉验证绘图及原理实践 分类:机器学习Sklearn
- mybatis入门基础(七)----延迟加载
- LINUX 指令大全(自用版)
- ubuntu更新后无法进入桌面
- 正则化方法:L1和L2 regularization、数据集扩增、dropout
- 谈谈我对封装,继承,抽象类,接口的理解
- java web 访问静态资源时注意设置 其访问权限,不然就访问不了