NULL vs 0 - a possible approach

guy at rlgvax.UUCP guy at rlgvax.UUCP
Tue Jan 31 14:44:35 AEST 1984


> There seem to be at least three objects around that need to
> be null pointers, and they don't always have the same type
> (at least on 68000 and other  strange machines.)

Unfortunately, there aren't three kinds of null pointer.  There are an infinite
number of them, because there are an infinite number of data types in C and
hence an infinite number of pointer types to point to them.  So defining
three kinds of NULL really doesn't solve the problem.  (Also, #define NULL 0
isn't defining a null pointer, it's defining an *integer* 0.  The rules don't
say that "0" is a null pointer, they say that when 0 appears in certain
expressions - assignments, comparisons - it is coerced into a pointer which is
guaranteed not to point to anything.)

Ask "lint", it'll tell you that the various kinds of null pointers *never*
have the same type, and that a pointer *never* has the same type as an "int".

There already exists a solution to the null pointer problem; run code through
"lint" and add casts when it complains about mismatched argument types.  Or,
even better, put the casts in *before* "lint" gets to complain.  C may not
have strong type-checking, but let's pretend it does whenever it yields
better code.

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



More information about the Comp.unix.wizards mailing list