Skip to main content
Associate III
February 20, 2025
Solved

if-block brace ignored...why?

  • February 20, 2025
  • 3 replies
  • 1052 views

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?

Best answer by White_Fox

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.

3 replies

Pavel A.
Super User
February 20, 2025

Try to step in instruction mode (disassembly).

 

TDK
Super User
February 20, 2025

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""."
Tesla DeLorean
Guru
February 20, 2025

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 VenmoUp vote any posts that you find helpful, it shows what's working..
White_FoxAuthorBest answer
Associate III
February 21, 2025

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.