...
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 | ||||
---|---|---|---|---|
| ||||
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 |
|
| Can detect violations of this rule when the | ||||||
Compass/ROSE |
|
|
| ||||||
| 344 S | Fully implemented. | |||||||
PRQA QA·CQA-C |
| 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
...