Stephane Caron

Static variables must be used in "for" loop ?

Discussion created by Stephane Caron on Mar 14, 2008
Latest reply on Jan 11, 2016 by Pedro Gonzaga da Silva Jr
Hello,
In my program, I noticed that when I use a for loop, it doesn't exit the loop unless the variable is declared static! The data in that variable seems to be inconsistent: it's impossible to check the variable's content in the debugger if that variable is not declared static, it shows *unknown error Ò100428Ó* in the expressions window and "No local variable" in the "Variables Live" section of the debugger.
 
Not working example: stay in the loop infinitely
int i;
for(i = 0; i < 10; i++)
{
    DoSomething();
}
 
Working example: loop 10 times then exit
static int i;
for(i = 0; i < 10; i++)
{
    DoSomething();
}
 
I use CodeWarrior for ColdFire, Version 7.0. build 15.
Maybe it's just a project setting, I don't find which one.
Thanks,
Frelon

Outcomes