Volatile (computer programming): Difference between revisions

Content deleted Content added
In C and C++: no optimisation for volatile
Line 13:
*allow uses of variables between <code>[[setjmp]]</code> and <code>longjmp</code>
*allow uses of <code>sig_atomic_t</code> variables in signal handlers.
 
Since variables marked as volatile are prone to change outside the standard flow of code, the compiler has to perform every read and write to the variable as indicated by the code. Any access to volatile variables cannot be optimised away, e.g. by use of registers for storage of intermediate values.
 
While intended by both C and C++, the C standards fail to express that the <code>volatile</code> semantics refer to the lvalue, not the referenced object. The respective defect report ''DR&nbsp;476'' (to C11) is still under review with [[C17 (C standard revision)|C17]].<ref>[http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2244.htm ''Clarification Request Summary for C11.''] Version 1.13, October 2017.</ref>