| ▲ | u8080 an hour ago | |||||||||||||||||||||||||||||||
When compiler decides something is UB aka "result of this code is not defined and could be any" it selects the most performant version of undefined behavior - doing nothing by optimizing code away. | ||||||||||||||||||||||||||||||||
| ▲ | shakna an hour ago | parent [-] | |||||||||||||||||||||||||||||||
The compiler is not free to remove accesses to something marked volatile - its defined as a side-effect. Volatile means something else may be acting here. Something else may install anything into the register at any time - and every time you access. The compiler is required to preserve the order of accesses. In almost every C compiler, today, there are almost no optimisations the moment a volatile is introduced, for this reason. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||