On Mon, 2011-01-24 at 13:19 +0100, Pierre Joye wrote: > > NULL is for pointers where 0 is for integer-like. > > Testing if a ptr is NULL should be done by testing for NULL or not > NULL. > > While compilers tolerate *ptr = 0 by casting 0 to NULL, any other > runtime check must use NULL. That's K&R 101.
The standard (quoting ISO/IEC 9899: TC2, but identical in other versions) states 6.3.2.3 Pointers 3 An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. [...] 6 Any pointer type may be converted to an integer type. Except as previously specified, the result is implementation-defined. and 7.17 Common definitions <stddef.h> 3 The macros are NULL which expands to an implementation-defined null pointer constant [...] So casting (int)0 to a (void*) results to a NULL pointer and is valid. The other way round is not specified, but implementation defined. By that Pierre's change is correct. Out of curiosity: I'm not aware of any implementation (which is in use) where this would be invalid. Anybody knows one? Sidenote: I think that one is even stricter in C++, as it binds the value of 0 to the NULL pointer. (Stroustrup suggests doing const int NULL 0; in §5.1.1 of his book, but I don't have the standard at hand) ... but C++ doesn't matter here. johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php