Stories
Slash Boxes
Comments

News for nerds, stuff that matters

Slashdot Log In

Log In

[ Create a new account ]

yellowstone (62484)

yellowstone
  (email not shown publicly)
about:blank

Journal of yellowstone (62484)

What is NULL?

[ #175169 ]
Tuesday June 26 2007, @02:48AM
Programming
This is the right:

#define NULL 0
This is wrong:

#define NULL ((void *)0)
Know why? In C++, this is supposed to be legal:

char *p = NULL;

With the first version, it is. With the second version, it's an error: there is no legal implicit conversion from void* to char*

<stddef.h>, <libio.h>, <glib/glib.h> -- I'm lookin' at you.

This discussion has been archived. No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login
Loading... please wait.
  • interesting crap creeps up in c/c++ every day. i wish i had an ssh right now into my linux box, it would be interesting to see if this would work in straight C.
    • C is a lot more casual about pointer conversion than C++. Here's what I get on my system for

      void foo()
      {
      char *p = (void *)0;
      }

      $ gcc -c foo.c -Wall
      foo.c: in function `foo':
      foo.c:3: warning: unused variable `p'
      $ g++ -c foo.c -Wall
      foo.c: in fun