开发者

why will the following error occur during compilation

As part of my program, I used following code:

///////////////
9开发者_开发百科8:::printf("%d",abc->stv)
//////////////
100::if(abc)
//////////////

(the following error was produced)

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


if (abc) tests whether abc is a null pointer or not.

The compiler is warning you that you've already assumed that abc is not a null pointer (by dereferencing it on line 98), which means either

  • the if (abc) test is redundant (because it will never be true) or
  • the dereferencing of abc on line 98 is potentially incorrect because abc might in fact be null.


If you test for abc it means to the compiler it might be null. Therefore dereferencing the pointer like in abc->stv is a possible error. A solution is to enclose the printf code inside the ifblock:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜