Problem with local  variables when debugging with CW 4.5 and 9s12X

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

Problem with local  variables when debugging with CW 4.5 and 9s12X

跳至解决方案
2,910 次查看
calou
Contributor III
Hello,
 
I have this function  :
BYTE GainToIndice(BYTE gain)
{
 BYTE i,g,ind;
 SBYTE diff;
 
 g=0xFF;
 for (i=0;i<BufConfig.nbgains;i++)
 {
   diff=BufConfig.gains[i].gain-gain;
   if (diff<0)
     diff=-diff;
   if(diff<g)
   {
     g=diff;
     ind=i;
   }
 }
}
 
I call it in my main program like GainToIndice(100)
 
When i debug it and look for example gain the value is 255. The value of i is always 52  whereas BufConfig.nbgains is 12, the value of g never changes (always 0). However the result is true.
I have tried a lot of -on optimisations but i didn't find the correct for my problem.
 
Thank you
 
Regards
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,481 次查看
calou
Contributor III
Hello again,
 
My problem is solved. It was a bug of my debugger. An update of the debugger software and now it is good.
 
Regards

在原帖中查看解决方案

0 项奖励
回复
4 回复数
1,481 次查看
CompilerGuru
NXP Employee
NXP Employee
I invented the missing parts (like the BufConfig struct) and stepped once through your code and it looks ok to me. i was incrementing properly.
The only reason I could imagine your behavior is if the debugger is not able to read the stack, but then it would not behave properly. Can you check if the location the debugger shows for the i variable is the one the code is using?
Also note that your code below does not have any effect at all. GainToIndice is missing a return, and also no global is ever written.

Daniel

PS: I take "However the result is true." as it steps through the code as you expect it too. There is no result or side effect in that code to observe.

0 项奖励
回复
1,481 次查看
calou
Contributor III
Hello Daniel,
 
In my code i forgot to paste return(ind).
I don't understand very well your question. When i put a breakpoint on diff=BufConfig.gains[i].gain-gain for the firs time
I have :
 diff = \x00 (0)
 g = \xD5 (213)
 gain = 'x' (120)
 i = \x00 (0)
 ind = \x95 (149)
It is very strange. And the values depends where i put the breakpoint!
I note too that when i check gain, its value is the result of BufConfig.gains[i].gain-gain
 
Thank you for help
 
Regards
 
0 项奖励
回复
1,482 次查看
calou
Contributor III
Hello again,
 
My problem is solved. It was a bug of my debugger. An update of the debugger software and now it is good.
 
Regards
0 项奖励
回复
1,481 次查看
CompilerGuru
NXP Employee
NXP Employee
Just wondering, which debugger do you use?

Daniel
0 项奖励
回复