Strictly speaking, any mutable variable whose access (read or write) cannot be optimized in accordance with the C standard. The standard says that access to the volatile object can have unknown side effects and that access to the volatile object must follow the rules of the abstract machine C (where all expressions are evaluated as given by their semantics).
From the mighty Standard (shock):
(C11, 6.7.3p7) "An object that has a mutable type can be modified in ways that are unknown to the implementation or other unknown side effects . Therefore, any expression referring to such an object is evaluated strictly in accordance with the rules of an abstract machine , as described in 5.1. 2.3. "
After that, even a simple variable initialization should be considered as access. Remember that the static specifier also initiates the initialization of the object (up to 0 ) and, thus, gets access.
Now, as you know, compilers behave differently with a mutable qualifier, and I think that many of them simply optimize most of the volatile objects of your sample program, except for those that have an explicit purpose ( = ).
source share