(char *)0 vs 0 vs (int *)0

Guy Harris guy at rlgvax.UUCP
Mon Feb 20 03:55:40 AEST 1984


>  On your Honeywell Level-6 GCOS system, there are a few interesting
>  sizeof values:
>  sizeof(int) == 2
>  sizeof(char *) == 6
>  sizeof(parm *) == 6
>  sizeof(int *)  == 4   /* withing structures */ Now what size of 0 do
> you want this time!  It takes Lint to figure out why it dumped core on
> well defined and working PDP-11 or VAX code.  Bleck.

Working yes, well-defined *no*.  *Correct* C code would work, because the
NULLs or 0s would be properly cast to (char *) or (int *) (what is parm *?).

C, as a language, has no trouble dealing with machines where there are several
kinds of pointers, none of which are the same size as each other or as an
"int".  Some *programmers* seem to have trouble with it; it has been stated
several times here that the simple and correct solution is to put a cast
in front of all NULL/0 values being passed as null pointers, but people
continue to object that "they shouldn't have to do it", or to concoct more
complicated solutions involving changing NULL to (char *)0 (which doesn't
even fix programs which don't use NULL but use 0, as they are allowed to do)
or adding a "null pointer" object to the language.

The C Reference Manual is *very* clear on these points, and so is "lint".  We
have just been given an example of why there is no "generic pointer" in the
C language; thanks to the author of that article for supplying a definitive
reason why casts or a facility to declare the types of the arguments to a
function is both necessary and sufficient.

Discussion closed.  OK?

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.unix.wizards mailing list