Abandon NULL for (0)

Dave Hammond daveh at marob.masa.com
Thu Oct 5 23:59:27 AEST 1989


In article <10839 at dasys1.UUCP> jpr at dasys1.UUCP (Jean-Pierre Radley) writes:
>I have found my code to more readable if I use these two defines:
>
>#define	NULLC (char *)0
>#define NULLF (FILE *)0
>

For the vast majority of data types, a single macro can produce
a properly cast null pointer:

#define NIL(t)	(t *)0

This produces fairly readable and maintainable code, as in:

fp = fopen("foo","r");
if (fp == NIL(FILE))
	{ ... }

The only pathological case which I define a separate macro for is
null pointer-to-function:

#define NILFUNC(t)	(t (*)())0

--
Dave Hammond
daveh at marob.masa.com



More information about the Comp.lang.c mailing list