M
Mark Hobley
How should I test for a null pointer within a C program?
Presumably the following will work:
if ( ptr == NULL ) { dosomething }
I have also seen the following, but I am unsure on this because can the value
of a null pointer be guaranteed to be zero? If it is not zero, does the pling
operator recognize this anyway, and the condition still works?
if ( !ptr ) { dosomething }
Or should I be using something else to test for a null pointer?
I am using C89, if that matters.
Mark.
Presumably the following will work:
if ( ptr == NULL ) { dosomething }
I have also seen the following, but I am unsure on this because can the value
of a null pointer be guaranteed to be zero? If it is not zero, does the pling
operator recognize this anyway, and the condition still works?
if ( !ptr ) { dosomething }
Or should I be using something else to test for a null pointer?
I am using C89, if that matters.
Mark.