Question
Unexpected code line jumping
Posted on October 09, 2012 at 09:52
Hi,
I'm experiencing a strange problem with IAR EWARM and STM32F4DISCOVERY. I have quite a deep nested 'if' function setup that is misbehaving. I have checked, double and triple checked the brackets and semicolons. I have also auto indented the function and it all matches up and looks fine. However when debugging the code, it seems to unexpectedly jump to lines (when stepping into [F11]), that it shouldnt. The problem seems to be irrelevant to the if statements, as it sometimesskips to a line without processing the proceeding line first
. This is hard to explain, see short example below g = 1; h = 2; if (g==1){ if (h==1){ i=1; j=2; k=3; }else if (h==2){ i=2; j=3; k=4; }else{ i=0; j=0; k=0; } }else{ i=8; j=9; k=10; } Obviously in this case the output should be i=2, j=3 and k=4. But when stepping through the code, the debugger will execute in the order given by the red numbers. In green is what should happen g = 1;1
h = 2;2
if (g==1){3
if (h==1){4
i=1; j=2; k=3; }else if (h==2){5
i=2;6
j=3;7
k=4;8
}else{ i=0; j=0; k=0; } }else{ i=8; j=9;6
k=10;7
} Yes that's right, it even skips i=8!! How can this be? At least the compiler seems to be consistent with where it skips. But how/why? Obviously my code is a lot bigger than this, but essentially this is whats happening. Could i be running out of memory/stack or something? I am using a lot of floats. I also have several timers running interrupts in the background, and this function itself is called via an interrupt. Help!? This is doing my head in... thanks!