Using NULL as an illegal pointer

Marc Elvy elvy at harvard.ARPA
Mon Jul 2 07:38:14 AEST 1984


While it does not seem to be standard practice in the UNIX world,
all of the C programmers (systems programmers or otherwise) here
have been encouraged to adopt explicit casting of NULL.  Sure, 0
is defined to be an illegal pointer, and every implementation of
NULL which I have ever seen has it equal to 0, but just in case
there exists a machine on which NULL is not an untyped (multityped?)
entity, we cast everything.  Besides, it is good documentation,
and does not break anything.  So my vote goes for

	char *string = (char *) NULL;		and
	return ((char *) NULL);			and
	return ((struct struct_name *) NULL);	etc.

rather than

	char *string = NULL;			and
	return (NULL);

Marc


		      Marc A. Elvy  ( elvy at harvard.{arpa,uucp} )
			     Aiken Computation Laboratory
				  Harvard University



More information about the Comp.lang.c mailing list