编译告警处理:dereferencing type-punned pointer will break strict-aliasing rules

时间:2015-08-25 14:02:58   收藏:0   阅读:1650

代码片段如下:

long triptime;

long now;

triptime = (now - *((uint32_t *)(icp->icmp_data)));

 

上述代码在编译时由于打开了-Wall -Os选项,编译器会上报如下告警

dereferencing type-punned pointer will break strict-aliasing rules

baidu无果后,决定自己实践来,于是做如下改动:

char *ptmp = icp->icmp_data;

triptime = (now - *((uint32_t *)(ptmp)));

至此,告警消失。

原文:http://www.cnblogs.com/sstudy-linux/p/4757110.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!