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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
1,953 Views
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
Labels (1)
Tags (1)
0 Kudos
1 Solution
524 Views
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

View solution in original post

0 Kudos
4 Replies
524 Views
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 Kudos
524 Views
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 Kudos
525 Views
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 Kudos
524 Views
CompilerGuru
NXP Employee
NXP Employee
Just wondering, which debugger do you use?

Daniel
0 Kudos