Microport Unix -- Large Model Problems

Doug Gwyn gwyn at brl-smoke.ARPA
Wed Nov 5 03:24:58 AEST 1986


In article <405 at maynard.UUCP> campbell at maynard.UUCP (Larry Campbell) writes:
>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.

How quickly people forget.

In pre-X3J11 C, no single data type is correct for null pointers in all
contexts, particularly in actual parameters to functions.  These should
ALWAYS be written as NULL (or 0) cast to pointers of the correct type.
The best definition of NULL in <stdio.h> for these implementations is the
integer constant 0.  Some of us would even argue that that is the only
completely correct choice.

In X3J11 C, if a function prototype is in scope, casting of function
parameters is automatically done, and either (void *)0 or 0 is a
correct definition for NULL.

I recommend that you assume that NULL is defined to be the int constant
0 (even if it isn't on your current system), and always cast it to the
correct pointer type when used as an actual parameter.  This practice
will continue to work under X3J11.



More information about the Comp.unix.wizards mailing list