Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. It is possible to reference a volatile object by using a non-volatile value, but the resulting behavior is undefined. The C standard, Section 6.7.3 [ISO/IEC 9899:2011], states:

If an attempt is made to refer to an object defined with a volatile-qualified type through use of an lvalue with non-volatile-qualified type, the behavior is undefined.

...

Casting away volatile allows access to an object through a non-volatile nonvolatile reference. This can result in undefined and perhaps unintended program behavior.

...

CERT C++ Secure Coding Standard: EXP32-CPP. Do not access a volatile object through a non-volatile reference

ISO/IEC 9899:2011 Section  Section 6.7.3, "Type qualifiers," and Section 6.5.16.1, "Simple assignment"

...