if-block brace ignored...why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-20 7:12 AM - last edited on ‎2025-02-20 9:25 AM by Tesla DeLorean
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?
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-21 12:17 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-20 7:43 AM
Try to step in instruction mode (disassembly).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-20 8:02 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-20 9:25 AM
What's the deal with the vertical bar? |
Generate a listing file and inspect the code generated
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-21 12:17 AM
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.
