comparing pointers to void functions

Rob Warnock rpw3 at rigden.wpd.sgi.com
Wed May 30 14:36:55 AEST 1990


In article <9454 at pt.cs.cmu.edu> cycy at 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 at sgi.com		rpw3 at pei.com
Silicon Graphics, Inc.		(415)335-1673		Protocol Engines, Inc.
2011 N. Shoreline Blvd.
Mountain View, CA  94039-7311



More information about the Comp.sys.sgi mailing list