POV-Ray : Newsgroups : povray.off-topic : C++ questions : Re: C++ questions Server Time
6 Sep 2024 23:20:35 EDT (-0400)
  Re: C++ questions  
From: Warp
Date: 24 Sep 2008 13:57:46
Message: <48da7f9a@news.povray.org>
Darren New <dne### [at] sanrrcom> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.