MISRA C:2023 Rule 11.3
A conversion shall not be performed between a pointer to object type and a pointer to a different object type
Since R2024a
Description
Rule Definition
A conversion shall not be performed between a pointer to object type and a pointer to a different object type.
Rationale
If a pointer to an object is converted into a pointer to a different object, the resulting pointer can be incorrectly aligned. The incorrect alignment causes undefined behavior.
Even if the conversion produces a pointer that is correctly aligned, the behavior can be undefined if the pointer is used to access an object.
As an exception, MISRA C:2023 standard permits converting a pointer to a non-qualified object type into a pointer to one of the following types:
char
signed char
unsigned char
Polyspace Implementation
Polyspace® reports a violation if an object is accessed by using a type that is different
than the type of the object. A violation is reported when the types of the pointer and
pointed-to object differ by a type qualifier such as const
.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Pointer Type Conversions |
Category: Required |
AGC Category: Required |