Content deleted Content added
→What can happen if volatile is not used?: Remove duplication to highlight the relevant change |
minor |
||
Line 34:
and the program will loop forever.
However, the address might represent a ___location that can be changed by other elements of the computer system. For example, it could be a [[hardware register]] of a device connected to the [[CPU]]. The value stored there could change at any time. Or, the variable may be modified by another [[thread (computer science)|thread]] or [[process (computing)|proces]] via [[shared memory]]. The above code would never detect such a change; without the volatile keyword, the compiler assumes the current program is the only part of the system that could cause the value to change. (This is by far the most common situation)
To prevent the compiler from modifying code in this way, the volatile keyword is used in the following manner:
|