我在
Understanding Strict Aliasing上注意到以下代码:
uint32_t swap_words( uint32_t arg ) { U32* in = (U32*)&arg; uint16_t lo = in->u16[0]; uint16_t hi = in->u16[1]; in->u16[0] = hi; in->u16[1] = lo; return (in->u32); }
据作者说,
The above source when compiled with GCC 4.0 with the
-Wstrict-aliasing=2 flag enabled will generate a warning. This warning is an example of a false positive. This type of cast is
allowed and will generate the appropriate code (see below). It is
documented clearly that -Wstrict-aliasing=2 may return false
positives.
我想知道什么是误报,我应该在别名变量时注意它吗?
以下是上面提到的“适当的代码(见下文)”,如果它是相关的:
在GNU C 4.0.0版(Apple Computer,Inc.build 5026)上使用-fstrict-aliasing -O3 -Wstrict-aliasing -std = c99编译(powerpc-apple-darwin8),
swap_words: stw r3,24(r1) ; Store arg lhz r0,24(r1) ; Load hi lhz r2,26(r1) ; Load lo sth r0,26(r1) ; Store result[1] = hi sth r2,24(r1) ; Store result[0] = lo lwz r3,24(r1) ; Load result blr ; Return
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。