At 2:42 AM +0000 2001/10/24, Trevor Harmon wrote:
>Jim Schram wrote:
>>...
>>Also be aware that accessing local variables declared as static from launch codes 
>that do not support globals will fail. You'll either corrupt memory and/or cause a 
>bus error, depending on what type of static variable is being accessed and how.
>>
>OK, that's exactly what I need to get straight because it's unusual (Palm-specific). 
>From reading the Palm OS Companion, it seems that sysAppLaunchCmdNormalLaunch (and 
>one or two others under certain conditions) is the only time globals, and static 
>locals, are accessible. But you say it depends on what static variable is being 
>accessed and how--could you please elaborate?

The no-globals launch codes are very Palm-specific, and they certainly can become a 
problem if you're not careful. You have to think about what functions will be called 
from which launch codes at all times.

When I say that accessing static variables during launch codes that do not provide 
globals can "corrupt memory and/or cause a bus error depending on what type of static 
variable is being accessed" I mean just that. Let's say you have a function which uses 
a static pointer to reference a structure in your app. If you attempt to de-reference 
that string during a non-globals launch code, you'll be de-referencing a random 
pointer value (because the offset from A5 which the code normally uses to access that 
static variable will be invalid... it's some other app's A5 at the time of the call). 
If that random value is odd, and you attempt to de-reference an Int16, you'll get a 
bus error. If you attempt to write to the structure referenced by that random pointer, 
you'll be randomly writing into memory somewhere, probably corrupting whatever's there 
(unless it just happens to point into the protected storage heap, or ROM).

Best Regards,

Jim Schram
Palm Incorporated
Partner Engineering


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

Reply via email to