Microport Unix -- Large Model Problems

Guy Harris guy at sun.uucp
Thu Nov 6 05:41:45 AEST 1986


> I wonder why stdio.h doesn't just declare NULL as "(char *) 0", or,
> in the brave new world of ANSI X-whatever, "(void *) 0"?  This should
> do all the right things.

No, it shouldn't.  Passing a "(char *)0" to a routine that expects an "int
*" of some sort is NOT guaranteed to work.  If, in fact, you have a machine
on which "char *" is longer than "int *", it is very unlikely to work.

In the brave new world of ANSI X3J11, the right thing to do is to use
function prototypes; if you do this, almost all the 0's will be
automatically converted into null pointers of the appropriate type by the
compiler.  (It still won't work for "execl"; if you hack NULL to be
"(char *)0", it fixes *this* case, but it may not work for some routine that
expects an "(int *)0" at the end of its argument list.)
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.unix.wizards mailing list