#defining NULL as (-1) in stdio

Peter X Moore moore at ic.berkeley.edu
Thu Jun 23 09:25:56 AEST 1988


Please, there are TWO issues: NULL and the integer constant 0. 
In pre-ANSI C, NULL HAS NO SPECIAL MEANING. It is not, REPEAT NOT,
part of the language in any way, shape, or form.  It is simply a
magic cookie defined in stdio.h and returned by some of the stdio functions
to signal an error.  Now most sane systems defined it to be 0, since 
assigning the constant 0 to a pointer IS guarenteed by the language to 
yeild a value that doesnt point to any valid object.  Therefore it has
been the habit of many programmers to use NULL as their distinguished
pointer value, relying on NULL being 0.  This was/is a bad idea, NULL 
didn't have to be 0.  And don't you feel strange having to import 
stdio.h into a file just to do pointer manipulation?

(Before you respond that K&R blessed such behavior, look again.  All the 
examples I have seen, they explicitly #define NULL to be 0 before using
it in any of their example code.)

ANSI evidently recognized that too many people have written too much 
code with this assumption, so they blessed it. In ANSI C NULL is defined
as the null pointer constant and defined in stddef.h instead of stdio.


	Peter Moore
	moore at Berkeley.EDU
	...!ucbvax!moore



More information about the Comp.lang.c mailing list