Hacker News new | ask | show | jobs
by TorKlingberg 3413 days ago
It's quite common in embedded systems to have the fault handler end with an infinite loop, to give the programmer a chance to attach a debugger an inspect the call stack. Sometimes this behavior is turned on or off with a debug flag, which can trigger this unexpected optimization if the flag is not a compile time constant.
3 comments

A halt instruction (HLT on x86) might also work.
You could also add a volatile declaration
You could always say

    if (flag) while (1);
Yes, that would make more sense. I have never seen this optimization actually bite anyone.