加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 什么是“误报”?

发布时间:2020-12-16 10:36:14 所属栏目:百科 来源:网络整理
导读:我在 Understanding Strict Aliasing上注意到以下代码: uint32_tswap_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 wh
我在 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

解决方法

这里的“误报”意味着警告不正确,并且实际上并不存在问题.假阳性是科学和医学中的标准术语,表示评估过程中的错误导致 mistaken detection of a condition tested.(假阴性将是在适当的情况下未发出警告.)

如果您确定警告是误报,则无需修复代码即可将其删除.您可能仍希望重新构建代码以避免编译警告(或者如果可能,请关闭该部分代码的警告).通常无警告的编译确保当出现真正的警告时,你应该注意,你不要错过它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读