CERT-EXP39-C_e
In this section:
Synopsis
Do not access a variable through a pointer of an incompatible type.
Enabled by default
Yes
Severity/Certainty
Medium/Low

Full description
Modifying a variable through a pointer of an incompatible type (other than unsigned char) can lead to unpredictable results. This check is identical to MISRAC2012-Rule-11.7.
Coding standards
- CERT EXP39-C
Do not access a variable through a pointer of an incompatible type
- MISRA C:2012 Rule-11.7
(Required) A cast shall not be performed between pointer to object and a non-integer arithmetic type
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int *p;
float f;
f = (float)p; /* Non-compliant */
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int *p;
short f;
f = (short)p;
}