Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!decwrl!sgi!rpw3@rigden.wpd.sgi.com From: rpw3@rigden.wpd.sgi.com (Rob Warnock) Newsgroups: comp.sys.sgi Subject: Re: comparing pointers to void functions Message-ID: <61180@sgi.sgi.com> Date: 30 May 90 04:36:55 GMT References: <9454@pt.cs.cmu.edu> Sender: rpw3@rigden.wpd.sgi.com Reply-To: rpw3@sgi.com (Rob Warnock) Organization: Silicon Graphics, Inc., Mountain View, CA Lines: 45 In article <9454@pt.cs.cmu.edu> cycy@isl1.ri.cmu.edu (Scum) writes: +--------------- | Okay, this is a better tested question. I'm having a problem trying to | determine if a pointer is pointing to a certain function. The pointer is | defined as an element in a structure thusly: | struct object { | void (*formstart) (); | } | As you can see, it is a pointer to a function which returns void. Now, I can | successfully invoke the function as: | struct object *thing; | (thing->formstart)(); | However, the compiler will not accept the following attempt to compare the | pointer to the address of the function, even though when they are printed | out, their values are the same: | if (thing->formstart == bgnpolygon) | The compiler says "operands of == have incompatible types". This doesn't seem | right to me. Can anyone out there help me.... Please? +--------------- Well, I originally thought it was because you needed to dereference the function pointer in order to compare (like you "theoretically" should have had to do in the call, but most compilers don't complain). That is: (*thing->formstart)(); and if (*thing->formstart == bgnpolygon) But on the 3.2 C compiler that still gives the error you saw. On a 3.3 (to be released) compiler, neither version of either form gives an error (and the generated code looks correct). So I guess it's "fixed in some to-be-determined release"... Maybe some compiler-type person can help you with a workaround. Or you might just try casting both sides of the compare to a (char *). [*Hack*] -Rob ----- Rob Warnock, MS-9U/510 rpw3@sgi.com rpw3@pei.com Silicon Graphics, Inc. (415)335-1673 Protocol Engines, Inc. 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311