Abandon NULL for (0)

Ian Cottam ian at ux.cs.man.ac.uk
Wed Sep 20 19:21:12 AEST 1989


Here is a C style suggestion that I am about to adopt (for you to
throw bricks at).  It is related to the issue of silly-little-macros,
but I have decided to use it after following discussions on the net
regarding implementations and users (!) that (re-)define NULL to
something stupid.  The original motivation for writing NULL rather
than 0 was, IMHO, to help the reader of a program text spot where the
denotation 0 meant ``the null pointer''.  I propose that the
integral constant expression

				(0)
be used instead of NULL.

Some example code:

/*
 * Initialise a new stack variable; return false iff init attempt fails
 */
bool
initstack(Stack *s)
{
	extern void *malloc(unsigned int);
	StackHeaderPtr tmp= (StackHeaderPtr)malloc(sizeof(StackHeader));

	if ( (0) == tmp )
		return false; /* malloc failed -- no store */
	else {
		tmp->top= (0); 	/* set stack empty */
		tmp->reserve= (StackElemPtr)malloc(sizeof(StackElem));
		if ( (0) == tmp->reserve )
			return false; /* malloc failure */
		else {
			*s= (Stack)tmp;
			return true;
		}
	}
}


-----------------------------------------------------------------
Ian Cottam, Room IT101, Department of Computer Science,
University of Manchester, Oxford Road, Manchester, M13 9PL, U.K.
Tel: (+44) 61-275 6157         FAX: (+44) 61-275-6280
ARPA: ian%cs.man.ac.uk at nss.cs.ucl.ac.uk   
JANET: ian at uk.ac.man.cs    UUCP: ..!mcvax!ukc!mur7!ian
-----------------------------------------------------------------



More information about the Comp.lang.c mailing list