Please use NULL instead of 0 whenever you have a pointer!

Robert Elz kre at mulga.SUN
Sun Feb 5 16:29:02 AEST 1984


If defining a new "magic object" (NIL) would solve the problem
at all, I'm sure that would have been done.

However, the constant '0' already is that magic object, as far
as the current syntax and semantics of C allow there to be one at all.

The compiler cannot pass the "correct" type of null pointer to
a function as an arg, unless (in the arg list) you tell it what
the correct type is, as otherwise it has no knowledge of what that
would be.  It is no good at all to pass the "widest" null pointer,
the only one that will do is the one that's just the right width.
(Given a wider pointer, of known type, its always possible to convert
it to another, narrower, pointer, but something has to do that
conversion.  Just dumping a wide pointer on the stack and hoping that
its going to mean the right thing in a called function simply won't work).

Should C be altered so that the compiler is able to determine what
the right type of an arg is at a function call (ie: forward declararions)
then '0' will serve the purpose of the "magic object" quite well
enough, as it does in assignments to pointers, and comparisons.

Robert Elz
decvax!mulga!kre



More information about the Comp.unix.wizards mailing list