Versions Compared

Key

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

...

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 Appendix J.)

Noncompliant Code Example

In this example, a volatile object is accessed through a non-volatile-qualified reference, resulting in undefined behavior.

Code Block
bgColor#FFcccc
langc
static volatile int **ipp;
static int *ip;
static volatile int i = 0;

printf("i = %d.\n", i);

ipp = &ip; /* produces warnings in modern compilers */
ipp = (int**) &ip; /* constraint violation, also produces warnings */
*ipp = &i; /* valid */
if (*ip != 0) { /* valid */
  /* ... */
}

...

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·CQA-C
Include Page
PRQA_V
PRQA_V
 Fully implemented

...

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

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

MISRA Rule 11.5

Bibliography

...