Volatile (computer programming): Difference between revisions

Content deleted Content added
Rescuing 2 sources and tagging 0 as dead.) #IABot (v2.0.9.3) (Whoop whoop pull up - 12955
Line 63:
 
===Optimization comparison in C===
The following C programs, and accompanying assembliesassembler language excerpts, demonstrate how the <code>volatile</code> keyword affects the compiler's output. The compiler in this case was [[GNU Compiler Collection|GCC]].
 
While observing the assembly code, it is clearly visible that the code generated with <code>volatile</code> objects is more verbose, making it longer so the nature of <code>volatile</code> objects can be fulfilled. The <code>volatile</code> keyword prevents the compiler from performing optimization on code involving volatile objects, thus ensuring that each volatile variable assignment and read has a corresponding memory access. Without the <code>volatile</code> keyword, the compiler knows a variable does not need to be reread from memory at each use, because there should not be any writes to its memory ___location from any other thread or process.