Quote:Original post by Anonymous Poster
NULL is either defined as (void*)0 or 0, so it IS null.
Not in C. (int)1.5f isn't 1.5f, and (void*)0 isn't 0. The C standard ensures that the 0 literal, when evaluated in a pointer context, is
transformed into a NULL pointer. In C, the NULL pointer may or may not be represented as an integer-sized block of memory filled with zero bits. When evaluated in a boolean context (such as an if) clause, any pointers but the NULL pointer evaluate to true, while the NULL pointer evaluates to false.
Note that C does not guarantee that:
- Setting all the bits of a pointer to zero creates a NULL pointer (as a matter of fact, several machines have a non-zero NULL pointer).
- Setting a pointer to a zero-valued variable (as in int x = 0; void* y = x;) creates a NULL pointer.
In short, the only safe way to create a NULL pointer in C is through the compile-time conversion of the 0 literal into a pointer. Merely setting the pointer to zero is not enough.