All,

A message from Ben Darnell a couple of weeks ago 
prompted me look up callbacks in Rodes' & McKeehan's 
book. It says:

   "The GCC compiler's calling conventions differ 
   from those in the Palm OS. In particular, the 
   GCC compiler expects at startup that it can set 
   up the A4 register (which it uses to access 
   global variables) and that it will remain set 
   throughout the life of the application. 
   Unfortunately, this is not true when a GCC 
   application calls a Palm OS routine that either 
   directly or indirectly calls back to a GCC 
   function (a callback).

   "The most common example of this occurrence is 
   when we've installed an event handler for a form 
   with  FrmSetEventHandler. Once we've done that, 
   a call to  FrmDispatchEvent (a Palm OS routine) 
   can call our form's event handler (a GCC function, 
   if we've compiled our application with GCC). 
   At this point, if our event handler tries to 
   access global variables, it'll cause a spectacular 
   application crash."

and then goes on to talk about the CALLBACK_PROLOGUE and 
CALLBACK_EPILOGUE macros.

Before discovering this, however, I wrote three non-
trivial applications using GCC but without these macros.  
They each access global and static variables, either 
directly in the event-handlers or in other functions
these call, but they seem to survive testing (both real 
and POSE/gremlin) and field use under OS3.0 and 3.3 
without crashing, spectacularly or otherwise.

Have now inserted the macros (which at least don't break 
anything) but would be interested if anyone can confirm 
that they really are necessary and, if so, in what 
circumstances.

Regards, Nick


-----Original Message-----
From: Ben Darnell [mailto:[EMAIL PROTECTED]]
Sent: Saturday, 18 December 1999 4:08
To: [EMAIL PROTECTED]
Subject: Re: GCC/Callbacks

On Thu, Dec 16, 1999 at 04:35:07PM -0500, Thomas Ward wrote:
> Hi All,
> 
> I have a routine that in some places in my code I call directly, and in
> other places I call via a callback. Is there any reason why that shouldn't
> work? Since I am using GCC, do I need to put CALLBACK_PROLOGUE and
> CALLBACK_EPILOGUE in such a routine? Can it cause a problem to have
> CALLBACK_PROLOGUE and CALLBACK_EPILOGUE where they are NOT needed?

Functions called by your code do not need CALLBACK_{PRO,EPI}LOGUE,
although there is no problem with having them unnecessarily (as long as
they are properly balanced - e.g. you must have a CALLBACK_EPILOGUE
before every return).  Functions called by PalmOS (e.g. form event
handlers, list draw functions) must have CALLBACK_{PRO,EPI}LOGUE if they
access global variables.  

-Ben
-- 
Ben Darnell              [EMAIL PROTECTED]
http://thoughtstream.org

Reply via email to