CERT-EXP40-C_a
In this section:
Synopsis
Do not modify constant objects.
Enabled by default
Yes
Severity/Certainty
Low/Low

Full description
If an attempt is made to modify an object defined with a const-qualified type through use of an lvalue with non-const-qualified type, the behavior is undefined.
Coding standards
- CERT EXP40-C
Do not modify constant values
Code examples
The following code example fails the check and will give a warning:
const int **ipp;
int *ip;
const int i = 42;
void example(void) {
ipp = &ip; /* Constraint violation */
*ipp = &i; /* Valid */
*ip = 0; /* Modifies constant i (was 42) */
}
The following code example passes the check and will not give a warning about this issue:
int **ipp;
int *ip;
int i = 42;
void example(void) {
ipp = &ip; /* Valid */
*ipp = &i; /* Valid */
*ip = 0; /* Valid */
}