On January 4, 2003 10:28 pm, Francois Gouget wrote:
A few handle types escaped the script the first time around. So here is an updated version that will catch them. The updated version will also catch casts of NULL to LP{C,W,wC}STR and LPVOID.
Why not just use 0 instead of NULL? Does it make any difference?
On Sun, 5 Jan 2003, Dimitrie O. Paun wrote:
On January 4, 2003 10:28 pm, Francois Gouget wrote:
A few handle types escaped the script the first time around. So here is an updated version that will catch them. The updated version will also catch casts of NULL to LP{C,W,wC}STR and LPVOID.
Why not just use 0 instead of NULL? Does it make any difference?
For the C/C++ compilers it does not make a difference, but to me it does (maybe because I've used languages with stronger typing than C a lot). For me 0 is an integer and thus it is wrong to assign it to a pointer. The compiler agrees with me for all non-zero integers but makes an exception for 0; 'for convenience's sake', or perhaps for historical reasons. NULL is a pointer so that's the right thing to use to initialize a pointer.
Similarly I prefer '\0' to 0 even if the compiler does not care.
On January 5, 2003 03:35 am, Francois Gouget wrote:
For me 0 is an integer and thus it is wrong to assign it to a pointer. The compiler agrees with me for all non-zero integers but makes an exception for 0; 'for convenience's sake', or perhaps for historical reasons. NULL is a pointer so that's the right thing to use to initialize a pointer.
I used to think this way years ago, but I have relaxed my position. Zero is fundamentally built into the language so deep, that playing with tricks like NULL and '\0' seem like a waste of time.
Moreover, I seem to remember some arguments sometime ago about 0 being actually preferred to NULL, at least in C++.
Bottom like, it seems to me there is little point in having a different names for the same thing: zero. In fact, I'd say it's bad from a theoretical standpoint (and no, I don't much care for the stronger typing argument, it buys you nothing in this case).
But if it makes you happy... :)
Zero is fundamentally built into the language so deep, that playing with tricks like NULL and '\0' seem like a waste of time.
FWIW I agree.
In C the character '0' appearing in a source file is the correct denotation for a 'null' pointer even when the bit-pattern for a null pointer isn't all zeros.
ie the value assigned by 'ptr = 0;' could be different from that generated by 'int i = 0; ptr = (void *)i;'
Similarly 'if (ptr) ...' and 'if (!ptr) ...' are valid checks for a null pointer, save 8 bytes on the line and stop the (usually) erronous 'if (ptr = NULL) ...'.
David