Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!wuarchive!uunet!zephyr.ens.tek.com!tektronix!reed!intelhf!ichips!iwarp.intel.com!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Is there a NULL pointer to functions? Message-ID: <4416@inews.intel.com> Date: 25 May 91 23:37:05 GMT References: <1991May21.125639.10052@umiami.ir.miami.edu> Sender: news@inews.intel.com Distribution: na Organization: Intel Corp, Chandler, AZ Lines: 36 In article <1991May21.125639.10052@umiami.ir.miami.edu> devebw9f@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."