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 type1 .
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 |
Version History
Introduced in R2024aSee Also
Check MISRA C:2023
(-misra-c-2023)
| MISRA C:2023 Rule
11.4
| MISRA C:2023 Rule
11.5
| MISRA C:2023 Rule
11.8
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.