[英]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)
测试是多余的(因为它永远不会为真)或 abc
的取消引用可能不正确,因为abc
实际上可能为null。 如果测试abc
,则对编译器意味着它可能为null。 因此,像abc->stv
那样取消引用指针是可能的错误。 一种解决方案是将printf
代码包含在if
块内:
if(abc)
{
printf("%d",abc->stv)
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.