CERT-EXP32-C
In this section:
Synopsis
Do not access a volatile object through a nonvolatile reference.
Enabled by default
Yes
Severity/Certainty
Low/High

Full description
An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Referencing a volatile object by using a non-volatile lvalue is undefined behavior.
Coding standards
- CERT EXP32-C
Do not access a volatile object through a non-volatile reference
Code examples
The following code example fails the check and will give a warning:
#include <stdio.h>
void func(void) {
static volatile int **ipp;
static int *ip;
static volatile int i = 0;
printf("i = %d.\n", i);
ipp = &ip; /* May produce a warning diagnostic */
ipp = (int**) &ip; /* Constraint violation; may produce a warning diagnostic */
*ipp = &i; /* Valid */
if (*ip != 0) { /* Valid */
/* ... */
}
}
The following code example passes the check and will not give a warning about this issue:
#include <stdio.h>
void func(void) {
static volatile int **ipp;
static volatile int *ip;
static volatile int i = 0;
printf("i = %d.\n", i);
ipp = &ip;
*ipp = &i;
if (*ip != 0) {
/* ... */
}
}