Volatile (keyword): Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
mNo edit summary
Line 1: Line 1:
== Definition ==
== Definition ==


The volatile statement gives an indication to the compiler that it should always perform a read or write to a variable or memory without caching it locally. It also ensures that the order of changes is preserved and not altered by the optimizer, and that apparently redundant code is optimized away.
The volatile keyword gives an indication to the compiler/optimizer that it should always perform a read or write to a variable or memory without caching it locally. It also ensures that the order of changes is preserved and not altered by the optimizer, and that apparently redundant code is not optimized away.


== The basics ==
== The basics ==
Line 82: Line 82:
}
}


Also see an example code where the volatile keyword is crucial (reading/writing to hardware registers): [[APIC#IO_APIC_Configuration|APIC]]
Also see the [[APIC#IO_APIC_Configuration|APIC example code]] where the volatile keyword is crucial (reading/writing to hardware registers).