Let's define our own NULL II

Bob Devine devine at cookie.dec.com
Sat Jun 25 08:43:07 AEST 1988


navtech!mark wrote:
> I am not asking about what is a legal definition of NULL.  I am
> asking whether one should define NULL in a product-wide header file *just* so
> that people won't have to include <stdio.h> if they only need a definition of
> "NULL" in a module.

  Quick answer: "It depends".  If every file is including stdio.h
(or stddef.h for ANSI-C) anyway then what is the use of having 
another include file?  This all devolves to the point that some
common file *has* to be included anyway: yours or the standard file.

  However if you already do have a project-wide include file, you
could make your own definition for NULL (you can choose any value
for it as long as it is 0 ;-)

  But then I never use NULL.  I use 0 cast appropriately because
that is both correct and, I believe, more informative to readers.
There is no single definition of NULL that is portable and correct
in every situation.  A cast must be used in some situations on
some machine for some functions.  Casts in C are easy to write.

Bob Devine



More information about the Comp.lang.c mailing list