if (p), where p is a pointer - PLEASE READ

Henry Spencer henry at utzoo.UUCP
Thu Sep 19 03:00:27 AEST 1985


> Well, now we come to the can of worms which causes some implementations to
> #define NULL (char *) 0: machines where pointers occupy more space than ints.
> In these implementations, foo(NULL) is absolutely incorrect (duplicate paren'd
> comment from previous paragraph) (and try porting "typical" code to such
> machines; but I digress).
> 
> ...  The solution may be that NULL should be 0L (but what
> about the venerable old PDP-11?  In that case, foo(NULL) passes too much stuff
> on the stack.  So, what is *the* answer?)....

*The* answer is that foo(NULL) is absolutely incorrect on any machine.
The proper way to write this is foo((char *)NULL).  The only portable way
to get something that looks like a NULL pointer of the proper type onto
the stack, is to put a NULL pointer of the proper type onto the stack
explicitly.  There are no shortcuts on this one.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list