Jim Schram wrote:

>Regarding static functions... you'll see a lot of this because it's good to hide the 
>existence of all functions that you don't explicitly wish to be exposed. Another way 
>of saying this is... that you want to mark all functions *private* except for those 
>that you explicitly want to mark as *public* and therefore be exposed outside the 
>source files in which they reside.
>
That's fine, but IMHO if programmers want this sort of feature, they may 
as well go with a higher level OO language. It's just strange to me that 
Palm OS code is the only place I've seen this sort of function hiding in 
C practiced regularly.

>There are several reasons why you might choose to make a local variable static. 
>Usually it's because a function requires some sort of "context" between calls to it 
>in your application, but by using static you avoid having to explicitly declare and 
>reference a global variable in some header file somewhere.
>
>Another reason might be for its stack-saving behavior with recursive functions. For 
>example, a recursive routine which declares a local variable static and uses that 
>variable each time it's called, will see that variable remain modified each time the 
>function returns from the recursive call. On the other hand, not declaring that 
>variable static will allow for a unique instance of it during every recursive call, 
>thus the variable will maintain its value each time the function returns from a 
>recursive call. But this has the disadvantage of using additional stack space during 
>each recursion, which could cause stack overflow errors in your application unless 
>the recursion is carefully limited.
>
Yes, those are all of the standard reasons to use static local 
variables, but I was referring to static global variables, which is what 
I always see in Palm OS code.

>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?

Trevor




-- 
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