We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I AM NOT UNDERSTANDING THE SITUATION WHEN SHOULD I USE "VOLATILE" WITH VARIABLES ???
In practice, compiler writers - especially embedded compiler writers - probably realise that their customers do make use of such loops, and so they choose not to.
Optimising away writes to a volatile variable would always be at least a straight violation of the programmer's expressed will, even if the standard can be bent into seemingly allowing it.
Even setting aside volatile, the GCC guys have a particularly clever idea about optimizing away entire loops: if a non-empty loop body was optimized away, the loop itself is removed, too. If the loop body was empty in the first place, they leave the entire loop alone, under the assumption that nobody would write an empty loop lest they really mean it.