MISRA C:2012 Rule 11.3
A conversion shall not be performed between a pointer to object type and a pointer to a different object type
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 cast 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:2012 standard permits converting a pointer to a
non-atomic
qualified object type into a pointer to one of the following types:
char
signed char
unsigned char
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 R2014bSee Also
MISRA C:2012 Rule 11.4
| MISRA C:2012 Rule 11.5
| MISRA C:2012 Rule 11.8
| Check MISRA C:2012 (-misra3)
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.