cancel
Showing results for 
Search instead for 
Did you mean: 

if-block brace ignored...why?

White_Fox
Associate III

Hi guys

In the picture, you can see a code fragment in debugging mode. You also may see, that the controller is forced to stop at line 476, the if statement.

Now the problem: I want to enter the if-branch, if the function returns with the READY typedef enum value. The function returns correctly the READY value, but does never jump into the if-branch. If I trigger the next step, the programm continues at line 482.

I tried many things already, including reading from a volatile variable instead of my function, with always the same result.

Does anyone an idea, why?

1 ACCEPTED SOLUTION

Accepted Solutions

Oh dear...the rubber duck found the solution.

The functions in the if-branch are out-optimized by the compiler (I wondered about the empty assembly before). Both functions contain some code, but I removed some defines and global variables the day before, which are also used in these functions. After whiping the global variables out, the functions just declare some variables and iterate in a loop, but do no write operations outside the functions anymore - so the compiler removed them completly (and is right with this).

Sorry for that.

View solution in original post

4 REPLIES 4
Pavel A.
Evangelist III

Try to step in instruction mode (disassembly).

 

TDK
Guru

Compile using the debug configuration. In release, things get optimized away. If function returns READY, the if block will be executed even if it may not stop there during the debugger single stepping. Recheck your assumptions there the compiler is robust.

If you feel a post has answered your question, please click "Accept as Solution".

What's the deal with the vertical bar?  |

Generate a listing file and inspect the code generated

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Oh dear...the rubber duck found the solution.

The functions in the if-branch are out-optimized by the compiler (I wondered about the empty assembly before). Both functions contain some code, but I removed some defines and global variables the day before, which are also used in these functions. After whiping the global variables out, the functions just declare some variables and iterate in a loop, but do no write operations outside the functions anymore - so the compiler removed them completly (and is right with this).

Sorry for that.