|
 |
Darren New <dne### [at] san rr com> wrote:
> > So I say "int *x = 0;" and then later I can check that "if (x == 0) ..."?
> Yes. Note that in each case, that's technically a cast. The bit pattern
> of the pointer doesn't have to be zeros. If it's a null pointer, casting
> it to an integer gives you zero, and casting the integer 0 to a pointer
> gives you null.
> At least in C, the "NULL" macro is more commonly used to me "a pointer
> that when cast to an integer yields zero." I think C++ changed this
> when it improved the type system.
The next C++ standard will actually introduce the keyword nullptr
to better disambiguate between the integer 0 and the null pointer.
Currently if you have this:
#include <cstddef>
void foo(int);
void foo(int*);
void main()
{
foo(NULL);
}
the foo(int) function will be called (and the compiler might give you a
warning about this if it's smart enough).
With the next standard you can write:
foo(nullptr);
and the foo(int*) function will be called.
--
- Warp
Post a reply to this message
|
 |