CERT-EXP39-C_b
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.1.
Coding standards
- CERT EXP39-C
Do not access a variable through a pointer of an incompatible type
- MISRA C:2012 Rule-11.1
(Required) Conversions shall not be performed between a pointer to a function and any other type
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
void example(void) {
int (*fptr)(int,int);
(int*)fptr;
}
The following code example passes the check and will not give a warning about this issue:
typedef void ( *fp16 ) ( int n );
typedef fp16 ( *pfp16 ) ( void );
void example(void) {
pfp16 pfp1;
( void ) ( *pfp1 ( ) ); /* Compliant - exception 2 - cast function
* pointer into void */
}