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 nonvolatile value, but the resulting behavior is undefined. The C standardStandard, 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.

(See also undefined behavior 65 of in Appendix J of the C Standard.)

Noncompliant Code Example

...

Tool

Version

Checker

Description

GCC

Include Page
GCC_V
GCC_V

 

Can detect violations of this rule when the -Wcast-qual flag is used.

Compass/ROSE

 

 

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V

344 S

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V
0312Fully implemented.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

...

EXP32-CPP. Do not access a volatile object through a non-volatile reference
ISO/IEC TR 24772Pointer casting and pointer type changes [HFC] and Type system [IHN]
MISRA-CRule 11.5

Bibliography

...

]Section 6.7.3, "Type

...

Qualifiers," and Section 6.5.16.1, "Simple

...

ISO/IEC TR 24772 "HFC Pointer casting and pointer type changes" and "IHN Type system"

MISRA Rule 11.5

...

Assignment"