Abandon NULL for (0)

Henry Spencer henry at utzoo.uucp
Sat Sep 23 06:00:49 AEST 1989


In article <14718 at bfmny0.UU.NET> tneff at bfmny0.UU.NET (Tom Neff) writes:
>However (0) is not explicitly cast to a pointer type, as NULL may be
>presumed to be when appropriate...

Sigh.  WRONG.  You cannot presume that the two will differ in behavior,
because one of the two possible definitions for NULL is `0'.  In all
contexts except arguments to a function, either form will get converted
automatically.  In that context, it depends on whether you have an ANSI
function prototype visible at the time.  If yes, both forms will be
converted.  If no, neither will be converted.

>For instance if I refer to, but do not
>declare or define, an external routine that accepts a single pointer as
>its argument, by saying myproc((0)), the compiler will Miranda it into a
>regular int, rather that ((void *) 0), which might have a different size
>and representation.

Which is true but quite irrelevant, since there is no guarantee at all
that the size and representation of `(void *) 0' will be right for some
arbitrary pointer type.  (There is a guarantee that it will be right for
`char *', but that does not generalize to, say, `int *'.)
-- 
"Where is D.D. Harriman now,   |     Henry Spencer at U of Toronto Zoology
when we really *need* him?"    | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list