Skip to main content
1 of 3
Kaz
  • 3.7k
  • 1
  • 21
  • 32

You can skip the check when you can convince yourself somehow that the pointer cannot possibly be null.

Usually, null pointer checks are implemented in code in which null is expected to appear as an indicator that an object is currently not available or whatever.

Note that null isn't an invalid pointer value; it is just invalid from the point of view of dereferencing. What I'm getting at is that there are many ways in C for a pointer to be invalid which are not detectable in any portable way.

For instance, a pointer value obtained from uninitialized or indeterminate memory, or a pointer obtained via some shady conversion.

So in the end, you have to just get it right.

Kaz
  • 3.7k
  • 1
  • 21
  • 32