Abandon NULL for (0)

Dave Jones djones at megatest.UUCP
Sat Oct 7 07:14:37 AEST 1989


>From article <15571 at nswitgould.cs.uts.oz>, by karl_auer_%7801.801 at fidogate.fido.oz (1):

> There is another good reason not to use '(0)' - in some
> implementations of C, pointers can have different sizes ...


Aaaaarrrrggggghh!!!!  Will this never cease?

On many (most? all?) Unixes, NULL has nothing at all to do with pointers.

Zip.

Nada.

Zilch.

It is just a silly little macro which means 0. Look it up. It happens
to reside in the stdio.h header-file, probably because somebody or
another back in antiquity thought that was a cute way to say "0".

Usually the compiler will figure out that you need a pointer, and
explicitly cast the zero to a pointer type. But you must 
always cast the 0 (a.k.a NULL) to a pointer explicitly in function
parameter lists, unless you have ANSII prototypes, and there is one
in scope. Even then I would cast it explicitly, for safety -- the
prototype might get dropped or changed -- and for clarity.

Say,

      (void*)0

or

      (char*)0

or
      (caddr_t)0

or
      (FILE*)0

or whatever.



More information about the Comp.lang.c mailing list