i am working on a homework and since our constraints are really strict i need to check for NULL
pointers everywhere if i want 100%. So i made a little inlined function which checks pointers for NULL
:
static inline void exit_on_null(void* ptr, const char* msg) {
if ( ! ptr ) {
printf("%s\n", msg);
exit(1);
}
}
Now i asked myself is it safe to do so? From the standard i know it is save to cast a pointer to void*
and back and receive the original pointer. Does that give that the void*
version of the pointer is still comparable to NULL
or is there some pitfall i can run in? For example is the following always true?
ptr = NULL
(void*) ptr == NULL