Is there a NULL pointer to functions?

Edward Hinton hinton at gca.UUCP
Wed May 29 21:33:30 AEST 1991


In article <16269 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1991May21.125639.10052 at umiami.ir.miami.edu> devebw9f at miavax.ir.miami.edu writes:
>>As the subject heading says, is there a NULL pointer to functions?
>
>Sure, just cast 0 to the appropriate function-pointer type.
>
>>      if (fun != NULL)            /* Line with the warning. */
>
>	if ( fun != (void(*)(void))0 )

Now I'm going back a ways, but C doesn't necessarily define
NULL as 0, although it's been quite a while since I've seen
a system where it isn't.  However, I recall a system where 0 WAS a
valid address (small model on an 8086 based virtual memory system)
and NULL was defined to be -1.

Although this looks odd, I suggest:

if ( fun != (void(*)(void))NULL )

Then again, it wouldn't necessarily surprise me if a definition
of NULL existed for some C compiler on some machine to define
NULL in a way that it wouldn't like this combination of casts.
I haven't had to do this in ANSI C on any strange implementations yet.




More information about the Comp.lang.c mailing list