MISRA C:2012 Dir 4.8
If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hidden
Description
Rule Definition
If a pointer to a structure or union is never dereferenced within a translation unit, then the implementation of the object should be hidden1 .
Rationale
If a pointer to a structure or union is not dereferenced in a file, the implementation details of the structure or union need not be available in the translation unit for the file. You can hide the implementation details such as structure members and protect them from unintentional changes.
Define an opaque type that can be referenced via pointers but whose contents cannot be accessed.
Polyspace Implementation
If a structure or union is defined in a file or a header file included in the file, a pointer to this structure or union declared but the pointer never dereferenced in the file, the checker flags a coding rule violation. The structure or union definition should not be visible to this file.
If you see a violation of this rule on a structure definition, identify if you have defined a pointer to the structure in the same file or in a header file included in the file. Then check if you dereference the pointer anywhere in the file. If you do not dereference the pointer, the structure definition should be hidden from this file and included header files.
The size of a structure can change at run time. If the size of a structure is
computed using the sizeof()
operator in a translation unit,
Polyspace® assumes that the implementation of the structure is required in the
translation unit. If the implementation of this structure is present in the
translation unit, Polyspace does not report a violation.
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: Code design |
Category: Advisory |
AGC Category: Advisory |
Version History
Introduced in R2018a
See Also
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.