Content deleted Content added
→What can happen if volatile is not used?: Rephrasing |
→What can happen if volatile is not used?: Bring out difference between '1`' |
||
Line 13:
*addr = 0;
while (*addr !=
;
}</nowiki></pre>
In this example, the code sets the value stored at [[memory address|___location]] 100 in the computer system to 0. It then starts to poll the address until it changes to
An [[Compiler_optimization|optimizing]] compiler will assume that no other code will change the value stored in ___location 100 and so it will remain equal to 0. The compiler will then replace the [[program loop|while loop]] with something similar to this: -
Line 29:
*addr = 0;
while (1) /* 1 here means TRUE */
;
}</nowiki></pre>
Line 47:
*addr = 0;
while (*addr !=
;
}</nowiki></pre>
With this modification the code will remain as it is and the CPU will detect the change when it occurs.
==External links==
|