[comp.sys.mac.programmer] using function pointers in Think C 4.0?

phils@chaos.cs.brandeis.edu (Phil Shapiro) (10/30/90)

In article <1990Oct25.085518.21436@agate.berkeley.edu>
borton@garnet.berkeley.edu (Chris "Johann" Borton) writes:
>   In article <4427@iitmax.IIT.EDU> soudan@iitmax.iit.edu (Bassel
>Soudan) writes:
>   > [Code and examples deleted]
>   I ran into this too when I started out with this stuff.  Sorry,
>   there is no 
>   way (that I know of, at least) to get an honest function pointer for a
>   method, for one simple reason:  objects are (usually) handles.  I
>   haven't gone into the gory details of method table lookup etc., but
>   suffice to say that this is trying to get the address of something
>   that is part of a moveable block.
>
>   [More comments deleted]
>
>   -cbb Chris Borton -*- borton@garnet.berkeley.edu -*- Ph.D. student,

There is no way to get the address of a method (short of dispatching
the message yourself), and this is unfortunate.

However, the reason is not because it is part of a moveable block.
When ThC stores objects in handles (or pointers), it is the data (the
instance variables) that are heap allocated.  The methods are linked
in through an A5 jump table just like any other code -- you wouldn't
want multiple versions of your object's methods on the heap, since the
methods won't be modified.

So why can't you take the address of methods?  I think what you're
really after is pointer to *messages*.  That way, you could combine a
message with an object and that would generate your method call.
Unfortunately, this just isn't part of the language at this point.  If
you are ambitious, we provide the source code for message dispatching
(_msg() in oops.c); you could probably tweak this code to do what you
want.

	-phil
--
   Phil Shapiro                           Technical Support Analyst
   Language Products Group                     Symantec Corporation
		Internet: phils@chaos.cs.brandeis.edu