On Wed, Oct 16, 2002 at 10:34:22AM -0700, Grosch, Scott wrote:
> From my main program I'm going to call a function in my library.
> Can I pass that library a pointer to a function that's in my main
> app, and have the library call it?

You don't say what tools you are using, you don't say what kind of
library you are building, and I assume but am not 100% certain that the
main executable involved is a m68k Palm OS *application* and that there
are no armlets involved.  But the short answer is yes, of course.

While your application is executing, its code resources are locked down.
So the function pointer you construct will certainly remain valid, and
you can use it as a callback (in the generic sense) with your library
just fine.

What's a more interesting question is whether that function (in your
application) will be able to access its (the application's) global
variables, when it has been called via your shared library like this.

In the most likely case of what you are doing, your application will be
accessing its globals via %a5 and your system shared library will not
even have its own globals and won't disturb %a5 at all.  So in this case
the answer here is also yes, of course.

If you've manually cons'ed up some globals for your shared library,
you've probably arranged for it to access them via %a4 and again won't
disturb %a5.  So again no problem.

And, depending on your tools, there may be a few other cases that your
library falls into, such as the case in which you are writing a GLib.
See also http://prc-tools.sourceforge.net/cgi-bin/info/Initialising+A4 ,
which may or may not actually cast light on anything.

    John

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to