>From: "Robert C. Thayer" <[EMAIL PROTECTED]>
>Well before I make the call below to StrCopy, the value of of the CharPtr
>variable charRatio is 8.9... After the StrCopy call, the same variable is
>either null, or garbage.
>Why?
Here's what might be happening. One thing that you have to watch out for
when stepping through with the debugger is that variables' values may appear
to be garbage due to optimizations performed by the compiler. Basically,
local variables that you assume are allocated on the stack may actually be
optimized by being assigned to processor registers. Moreover, the compiler
is smart enough to know when a local variable is no longer used within a
function, and it may then use the var's assigned register for some other
purpose. Consider the following code:
Int16 i, j;
for (i = 0; i < 6; ++i) {
...
}
for (j = 0; j < 10; ++j) {
}
Now if "i" is not used again after the first loop, then the compiler might
use the same register for both i and j. So even though they appear
separately in the debugger's variable watch window, they are referring to
the same register and you will see both vars appear to change even though
only one at a time is being referenced in the source code! In some
development environments, a debug switch is used to force the compiler to
use stack locations for all local vars so that it is easier to debug the
program. However, Codewarrior can debug even an optimized program, but at
the expense of making variable tracking a bit more difficult.
BTW, any local var that is passed by reference anywhere in the function,
e.g. &some_var, must of course be allocated on the stack since you can't
pass a register by reference.
Doug Gordon
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html