Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!wuarchive!uunet!gca!hinton From: hinton@gca.UUCP (Edward Hinton) Newsgroups: comp.lang.c Subject: Re: Is there a NULL pointer to functions? Message-ID: <632@gca.UUCP> Date: 29 May 91 11:33:30 GMT References: <1991May21.125639.10052@umiami.ir.miami.edu> <16269@smoke.brl.mil> Organization: GCA Corporation, Andover MA Lines: 25 In article <16269@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: >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? > >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.