if(p)

Guy Harris guy at sun.uucp
Thu Oct 3 15:05:18 AEST 1985


> So when you say if(p) you're asking if it has a VALID or INVALID value.
> It's just that conveniently most machines have 0 as the INVALID value.

If you had a machine on which the bit pattern stored in an invalid pointer
was 0x12344321, the way to test whether a pointer is valid or not is

	if (p)	/* or if (p != 0) or if (p != NULL) */
		printf("valid\n");
	else
		printf("invalid\n");

The fact that "0" is converted to the appropriate pattern for an invalid
pointer (of the type in question) does not imply that those pointers have to
have a bit pattern of all zeroes.

	Guy Harris



More information about the Comp.lang.c mailing list