Chris Tutty wrote:
From: "Bryce Burrows" <[EMAIL PROTECTED]>
ahh something seriously screwy is going on with PODS
if (false == bFailed)
{
nCount ++;
}
bFailed is true , yet it heads on to the nCount++ line
I've found that with compiler optimisations small test code
often doesn't operate as you would expect because the
compiler eliminates code without side-effects or merges
code paths that resolve to the same end result.
What I mean is that if the code after the if () continues
on to a code section that also executes nCount ++; the
compiler might determine that the test is redundant.
That's a good insight. I have seen compilers optimize away
things that you didn't think they could, but then on further
inspection, you realize that the value of some variable
actually does not affect the end result.
In that case, I would actually recommend doing something that
will force the compiler to believe the value of whatever
variable does matter. Perhaps like this:
if (false == bFailed)
{
nCount++;
SysTaskDelay (nCount % 1);
}
Because the value of the expression containing nCount is used as an
argument to SysTaskDelay (an external function which is a black box
the compiler has no insight about or control over), the compiler
should conclude that the value of nCount does matter and must be
computed correctly.
Another approach is to turn off all inlining, optimization, etc.
when you build anything you'll run the debugger against, which
is always a good idea, although you are then debugging code that's
a bit different than what you'll use when you turn the optimizer
back on...
- Logan
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/