Path: utzoo!utgpu!watmath!clyde!att!pacbell!ames!ucsd!chem.ucsd.edu!tps
From: tps@chem.ucsd.edu (Tom Stockfisch)
Newsgroups: comp.lang.c
Subject: Re: pointers, tests, casts
Message-ID: <376@chem.ucsd.EDU>
Date: 2 Dec 88 08:00:22 GMT
References: <11130@dartvax.Dartmouth.EDU> <494@auspex.UUCP> <3340@tekcrl.CRL.TEK.COM>
Reply-To: tps@chem.ucsd.edu (Tom Stockfisch)
Organization: Chemistry Dept, UC San Diego
Lines: 28

In article <3340@tekcrl.CRL.TEK.COM> danw@tekchips.CRL.TEK.COM (Daniel E. Wilson) writes:
>In article <494@auspex.UUCP>, guy@auspex.UUCP (Guy Harris) writes:
>> >In assignments, a 0 or NULL is cast implicitly to the correct pointer
>
>  I tend to avoid the whole problem by defining a simple macro.  Simply
>by using this macro always I get a NULL pointer of the needed type.
>This does avoid bugs.
>
>     #define NIL(type) ((type *) NULL)

It also doesn't always work, e.g.
	
	NIL( int (*)[5] )

or

	NIL( void (*)() )

I use (type *)0 when passing arguments and NULL everywhere
else (except, of course, the null character should be
written '\0').
Then noone has to look up NIL() in a header
file, I don't have to make sure the header file is included
in virtually every source file I write, and it always works.

-- 

|| Tom Stockfisch, UCSD Chemistry	tps@chem.ucsd.edu