Null revisited (briefly)
Chris Torek
chris at mimsy.UUCP
Mon Feb 6 14:13:09 AEST 1989
In article <7630 at chinet.chi.il.us> les at chinet.chi.il.us
(Leslie Mikesell) writes:
>Does the (IMHO) incorrect cast of NULL to (char *) in some compilers
>stdio.h hurt anything in a correctly written program?
That (not just opinion) incorrect definition of NULL does indeed hurt.
For instance, given the (correct) C code:
#include <stdio.h>
int *ip = NULL;
the compiler should at least warn about the improper assignment of
(char *)0 to a variable of type (int *). A compiler with such a
definition is likely to warn about or refuse to compile a large number
of correct programs.
Once again, the *ONLY* correct definitions of NULL are
#define NULL 0
#define NULL 0L
#define NULL ((void *)0)
and possibly other constant expressions that evaluate to 0, 0L,
or (void *)0 anyway. (char *)0 is *not* a proper untyped nil pointer.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list