Casting call

Guy Harris guy at sun.uucp
Wed May 22 18:16:30 AEST 1985


> What you really want is a "typeof" operator:
> 
> #define FREE(ptr)     {  free((char *) ptr); ptr = (typeof ptr) NULL;  }

You don't need it.  If we were using ANSI C, we wouldn't need to cast
null pointers at all, except in calls to "execl" and the like, as long as
we declared the types of arguments to routines; the compiler would know that
a given routine expected a "char *" and would coerce a 0 passed to the
routine into a "(char *)0".  In this case, the compiler does know that
you're assigning 0 to a pointer of a particular type, and that it should
cast the 0 into a "(typeof ptr)0".

	Guy Harris



More information about the Comp.lang.c mailing list