Static variables must be used in "for" loop ?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Static variables must be used in "for" loop ?

2,784 次查看
Frelon
Contributor I
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
标签 (1)
标记 (1)
0 项奖励
回复
5 回复数

1,073 次查看
pedrogonzagadas
Contributor I

Hi people,

I had the same problem who Tom . The instruction who James answered   "Try Un-checking - Target Settings Pannel \  Coldfire Processor \Registor Coloring."

Worked for me too!

disabled_coloring.png

befor_configuraion.png

after_configuraion.png

Pedro Gonzaga .

0 项奖励
回复

1,073 次查看
RichTestardi
Senior Contributor II
Are you running CW7.0?  I noticed this when I upgraded from CW6.4 to CW7.0.
 
Most local variables were not displayed in the debugger, and I got the same error message.
 
The fix for me was to disable Register Coloring in the project settings, under Code Generation -> ColdFire Processor.
 
I hope it works for you.
 
-- Rich
 
0 项奖励
回复

1,073 次查看
RichTestardi
Senior Contributor II
However, I should add that in my case, the code behaved correctly -- only the debugger was confused.
 
So your issue might be different.
 
0 项奖励
回复

1,073 次查看
Frelon
Contributor I
For the local variables, you were right Rich, disabling Register Coloring allows me to see local variables, thanks!
 
For the "for loop" problem, I found the solution too: I previously added a delay loop like this in my code:
   asm
   {
      move  #4, d7
     
   Loop1uSec:
        
      subi #1, d7
      bne   Loop1uSec
   }
That code worked well, but it gives me the "for loop" bug later. I replaced that assembler function with one in C and now it works fine.
 
Frelon
0 项奖励
回复

1,073 次查看
CompilerGuru
NXP Employee
NXP Employee
Sounds like a stack overflow, could that be?
Or maybe the inproper use of different calling conventions.

Daniel
0 项奖励
回复