if (p), where p is a pointer (REAL portability)

Henry Spencer henry at utzoo.UUCP
Fri Sep 20 07:37:13 AEST 1985


> NULL *IS* defined as (char *)0 and SHOULD only be used in comparisons
> with character pointers!

Groan.  Wrong.  K&R page 97:

	#define NULL 0
	...
	We write NULL instead of zero... to indicate more clearly that
	this is a special value for a pointer...

Harbison & Steele, page 94:

	Standard header files usually define the preprocessor macro
	name NULL to be 0.

ANSI X3J11 draft of 30 April 1985, page 67:

	The macros are... NULL... which expands to a constant expression
	whose value compares equal to that of an integral constant
	expression with the value 0, which can be assigned to a pointer
	or used as an argument to represent the null pointer...

(Note that although the ANSI definition uses more complex weasel-wording
than the earlier ones, it still requires that NULL work for pointer types
in general.)
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry



More information about the Comp.lang.c mailing list