warning:dereferencing type-punned pointer will break strict-aliasing rules
来源:互联网 发布:滴滴架构 知乎 编辑:程序博客网 时间:2024/05/29 10:22
中文警告:提领类型双关的指针将破坏强重叠规则
warning:dereferencing type-punned pointer will break strict-aliasing rules
在 gcc 2.x 下编译没有任何 warning 信息的代码换到 gcc 3.x 版本下之后出现了类似的 warning。原因是 gcc 3 引入了 strict aliasing架构,当编译时使用了
gcc 3 manual 对于
简而言之, 在该参数激活的情况下,编译器希望不同类型的对象不会指向同一个地址。比如像这段代码:
int
someSetFunc((unsignedlong*)&retLen);
printf("ret len= %d\n",retLen);
由于 someSetFunc 的传入参数类型定义为
消灭的方法也不算复杂,正如 gcc manual 所示的那样,可以是采用 union的不同成员变量来完成类型的转换。上面那段代码可以改为:
union
{
int
unsignedlong
};
someSetFunc(&u_retLen.ptr);
printf("ret len= %d\n",u_retLen.retLen);
虽然会使源代码变得丑陋,但对于大部分已有的源代码来说,这可能是改动最小的方案了。而对于新写的代码来说,如何更好的设计函数的入口参数(比如使用void*)可能才是需要去思考的问题了。
转自:http://www.zeali.net/entry/454
- warning: dereferencing type-punned pointer will break strict-aliasing rules
- warning: dereferencing type-punned pointer will break strict-aliasing rules
- warning: dereferencing type-punned pointer will break strict-aliasing rules
- warning:dereferencing type-punned pointer will break strict-aliasing rules
- warning: dereferencing type-punned pointer will break strict-aliasing rules(转)
- warning: dereferencing type-punned pointer will break strict-aliasing rules(转)
- warning: dereferencing type-punned pointer will break strict-aliasing rules(转)
- warning: dereferencing type-punned pointer will break strict-aliasing rules(转)
- memcached 1.4.15 make error: dereferencing type-punned pointer will break strict-aliasing rules 解决方法
- memcached-1.4.5安装时候出现错误error: dereferencing type-punned pointer will break strict-aliasing
- warning: dereferencing pointer ** does break strict-aliasing rules
- does break strict-aliasing rules
- dereferencing pointer to incomplete type
- dereferencing pointer to incomplete type"
- dereferencing pointer to incomplete type
- dereferencing pointer to incomplete type
- dereferencing pointer to incomplete type
- dereferencing pointer to incomplete type
- mac系统下发布qt第三方的应用程序(opencv)
- flex socket.readObject() //flex读取java服务器端发送过来的对象
- Windbg内核调试下调试应用层
- 资源Android目录
- awk以列为关键词统计出现次数
- warning:dereferencing type-punned pointer will break strict-aliasing rules
- _com_util::ConvertBSTRToString BUG解决方案(转载)
- 打印
- NSArray,NSSet等集合类的使用
- Nano-X图形库
- Redis配置文件中文详解
- snprintf函数用法
- openGl API
- 遍历Map的四种方法