it’s just for experimental reasons, and my question is not about workarounds, just that issue is actually the issue
Because the point is:
the compiler must not care if variables are “volatile” !
So actually the code had to be compiled without out-optimizing the loops, and therefore I expected the LED to blink!
Obviously, you do not understand the deep workings of the compiler and how short-circuit situations are identified and optimized. The compiler is far smarter than I as I have been proven wrong more than a few times when I second-guessed what is happening.
IMO, just using volatile as an attribute does not imply that the compiler must execute a loop incrementing the variable if the variable is not subsequently referenced outside the loop… hence, why I suggested you print it.
When is a Volatile Object Accessed?
C has the concept of volatile objects. These are normally accessed by pointers and used for accessing hardware or inter-thread communication. The standard encourages compilers to refrain from optimizations concerning accesses to volatile objects, but leaves it implementation defined as to what constitutes a volatile access. The minimum requirement is that at a sequence point all previous accesses to volatile objects have stabilized and no subsequent accesses have occurred. Thus an implementation is free to reorder and combine volatile accesses that occur between sequence points, but cannot do so for accesses across a sequence point. The use of volatile does not allow you to violate the restriction on updating objects multiple times between two sequence points.