Abandon NULL for (0)

Chris Torek chris at mimsy.UUCP
Fri Oct 6 21:43:39 AEST 1989


In article <252B5E41.1244 at marob.masa.com> daveh at marob.masa.com (Dave Hammond)
writes:
[`#define NIL(t) (t *)0' works for most types]
>The only pathological case which I define a separate macro for is
>null pointer-to-function:
>
>#define NILFUNC(t)	(t (*)())0

Note that in Classic C, this is a `pointer to function returning t',
but in New C, this is a `pointer to function of unknown arguments
returning t' and that the latter type is Officially Frowned Upon.
One is supposed to write monstrosities like

	void (*signal(int, void (*)(int)))(int);

Then a nil pointer (which, incidentally, is not as an action defined
for signal(), although SIG_DFL is usually a nil pointer) of the
appropriate type can be made with

	#define	SIG_DFL	((void (*)(int)) 0)

It all gets a bit clearer with typedefs:

	typedef void (*pointer_to_signal_function)(int);
	pointer_to_signal_function signal(int, pointer_to_signal_function);
	#define	SIG_DFL	((pointer_to_signal_function) 0)

(except, of course, that implementors are not allowed to use the name
`pointer_to_signal_function'---you are more likely to see something like
the original, or like

	typedef void (*__sfp_t)(int);
	__sfp_t signal(int, __sfp_t);
	#define SIG_DFL ((__sfp_t) 0)

in your <signal.h>).
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list