NULL pointer
Alexis Dimitriadis
alexis at reed.UUCP
Tue Nov 19 15:27:15 AEST 1985
> #define NULL ((char *) 0)
>
> rather than arithmetic zero. This would make it work on machines which use a
> non-zero null pointer. I have tried doing this in a number of programs to
> examine the effect on lint and/or the generated code, and have yet to find a
> case where it caused a problem (although it did reveal a few genuine bugs in
> "working code").
What exactly did you try? Defining NULL this way generates _compiler_
errors whenever you use NULL in a context that requires anything other
than a char pointer, e.g. a comparison. The only case when it _fixes_
things is when NULL is a function argument, and the draft standard will
provide for function argument coercion, as well. Example:
#include <stdio.h>
#undef NULL
#define NULL ((char *)0)
main()
{
if (fopen("foo", "w") == NULL)
;
}
% cc t.c
"t.c", line 8: warning: illegal pointer combination
--Alexis Dimitriadis
--
_______________________________________________
As soon as I get a full time job, the opinions expressed above
will attach themselves to my employer, who will never be rid of
them again.
alexis @ reed
{decvax,ihnp4,ucbcad,uw-beaver}!tektronix!reed.UUCP
More information about the Comp.lang.c
mailing list