On Wednesday 20 April 2005 14:16, Jerry Feldman wrote:
On Tuesday 19 April 2005 7:39 pm, Philipp Thomas wrote:
That's from the pre-ANSI days, when void and 'void *' didn't exist. The C standard defines NULL to be (void *)0.
Not entirely true: "NULL which expands to an implementation-defined null pointer constant". ISO/IEC 9899:1999
A rather vague definition. I was recently looking at what to do with NULL in C++. So I looked it up in Stroustroup. In section 5.1.1 "Zero" there is the following paragraph:
In C, it has been popular to define a macro NULL to represent the zero pointer. Because of C++ tighter type checking, the use of plain 0, rather then and suggested NULL macro leads to fewer problems. If you feel you must use NULL, use "const int NULL = 0;" The const qualifer prevents accidental redefinition of NULL and ensures that NULL can be used where a constant is required.
I really don't understand what Bjarne means. Particularly the mention of 'tighter type checking' and 'fewever problems' seem odd. Of course macros are evil so that is a good reason not to use NULL. The ISO C++ standard only refers to NULL in the conext of the <cxxx> header files. The C++ language has true constants. First, every C++ function must be fully prototyped unlike C. NULL is a macro defined in stdio.h. In the C++ context, it might be more
On Wednesday 20 April 2005 11:38 am, Michael Stevens wrote:
proper to use:
const void * NULL = 0;
Then, the C++ NULL constant is a true pointer with a value of 0.
const int NULL = 0 is somewhat problematical in a 64-bit environment, since
pointers are 64-bits. But, since C++ is fully prototyped, it will be
widened appropriately.
--
Jerry Feldman