Is there a NULL pointer to functions?
Blair P. Houghton
bhoughto at pima.intel.com
Sun May 26 09:37:05 AEST 1991
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?
Yes.
>#define NULL ((void *) 0)
>
>void foo (void (*fun) (void))
>{
> if (fun != NULL) /* Line with the warning. */
> fun ();
>}
[...]
>when compiled with gcc generated the following message:
No, when compiled with (at least) 'gcc -ansi -pedantic', it
generates this message. I almost missed it by leaving
out the '-pedantic'...
>In function foo:
>warning: ANSI C forbids comparison of `void *' with function pointer
Someone should upgrade that message; they were correct, but
incomplete. ANSI C forbids comparison of function types
with any other types. It's just a result of the requirement
to compare only "compatible types." Use a cast to get the
correct type in the right-hand operand:
void foo (void (*fun) (void))
{
if ( fun != (void (*) (void))NULL )
fun ();
...
--Blair
"And a cast of thousands."
More information about the Comp.lang.c
mailing list