MISRA C:2023 Rule 11.2
Conversions shall not be performed between a pointer to an incomplete type and any other type
Since R2024a
Description
Rule Definition
Conversions shall not be performed between a pointer to an incomplete type and any other type.
Rationale
An incomplete type is a type that does not contain sufficient
information to determine its size. For example, the statement struct
s;
describes an incomplete type because the fields of s
are
not defined. The size of a variable of type s
cannot
be determined.
Conversions to or from a pointer to an incomplete type result in undefined behavior. Typically, a pointer to an incomplete type is used to hide the full representation of an object. This encapsulation is broken if another pointer is implicitly or explicitly cast to such a pointer.
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 R2024a