MISRAC2012-Rule-11.3
Synopsis
(Required) A cast shall not be performed between a pointer to object type and a pointer to a different object type A pointer to object type is cast to a pointer to a different object type. Conversions of this type might be invalid if the new pointer type requires a stricter alignment.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
A pointer to object type is cast to a pointer to a different object type. This check is identical to CERT-EXP39-C_d.
Coding standards
- CERT EXP39-C
Do not access a variable through a pointer of an incompatible type
- MISRA C:2012 Rule-11.3
(Required) A cast shall not be performed between a pointer to object type and a pointer to a different object type
Code examples
The following code example fails the check and will give a warning:
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
void example(void) {
uint8_t * p1;
uint32_t * p2;
p2 = (uint32_t *)p1;
}
The following code example passes the check and will not give a warning about this issue:
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
void example(void) {
uint8_t * p1;
uint8_t * p2;
p2 = (uint8_t *)p1;
}