Casting NULL?

dvadura at watdaisy.UUCP dvadura at watdaisy.UUCP
Sat Jan 24 00:27:31 AEST 1987


In article <3179 at brl-adm.ARPA> Peter Steele - Acadia writes:
>I have a question about pointers: I just recently read
>a C text where whenever NULL was passed as a parameter
>it was casted to the proper type.
>
>He claimed that
>this is required because pointers to different types of objects
>may not be the same size.

I don't know how common it is, but a simple solution is to define:

#define NIL(a) (a *)NULL;

when you need to pass a null pointer to an int or a char then say

	NIL( int ) or NIL( char )

this works for structs and other objects as well.

     	typedef foo { .... } BAR;

then NIL( BAR ) is a NULL pointer of type BAR.



More information about the Comp.lang.c mailing list