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
abcon line 98 is potentially incorrect becauseabcmight 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)
...
}
加载中,请稍侯......
精彩评论