pointers, tests, casts

Tom Stockfisch tps at chem.ucsd.edu
Fri Dec 2 18:00:22 AEST 1988


In article <3340 at tekcrl.CRL.TEK.COM> danw at tekchips.CRL.TEK.COM (Daniel E. Wilson) writes:
>In article <494 at auspex.UUCP>, guy at 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 at chem.ucsd.edu



More information about the Comp.lang.c mailing list