Peter Seebach and Simon Josefsson wrote:
> > Note that NULL could
> > be the same, or it could be already converted to (void *), so it depends on
> > the implementation whether:
> >
> >     printf("%p\n", NULL);
> >
> > is legit.  (Which means it's not portable...)
> 
> Indeed, and a quite realistic example of where this bug hits in practice
> is with the version-etc module where the final NULL needs to be
> explicitly casted to work properly on all systems, e.g.:
> 
>       version_etc (stdout, "gsasl", p, gsasl_check_version (NULL),
>                  "Simon Josefsson", (char *) NULL);

That's true when you consider only ISO C99.

But in POSIX, NULL is required to be (void *) 0. See
  <http://www.opengroup.org/onlinepubs/9699919799/basedefs/stddef.h.html>
"The macro shall expand to an integer constant expression with the value 0 cast
 to type void *."

Note that this can only for C. Whereas in C++, NULL cannot be (void *) 0, 
because
  char *p = NULL;
is valid C++, whereas
  char *p = (void *) 0;
is invalid (missing a cast). See ISO C++ section [conv.ptr].

Bruno


Reply via email to