繁体   English   中英

为什么在编译过程中会发生以下错误

[英]why will the following error occur during compilation

作为程序的一部分,我使用了以下代码:

///////////////
98:::printf("%d",abc->stv)
//////////////
100::if(abc)
//////////////

(产生了以下错误)

Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 100

if (abc)测试abc是否为空指针。

编译器警告您,您已经假定abc不是空指针(通过在第98行对其进行解引用),这意味着

  • if (abc)测试是多余的(因为它永远不会为真)或
  • 在第98行对abc的取消引用可能不正确,因为abc实际上可能为null。

如果测试abc ,则对编译器意味着它可能为null。 因此,像abc->stv那样取消引用指针是可能的错误。 一种解决方案是将printf代码包含在if块内:

if(abc)
{
    printf("%d",abc->stv)
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM