MISRA C++:2008 Rule 5-2-6
A cast shall not convert a pointer to a function to any other pointer type, including a pointer to function type
Description
Rule Definition
A cast shall not convert a pointer to a function to any other pointer type, including a pointer to function type.1
Rationale
Because calling a function through a pointer with incompatible type results in undefined behavior, the rule forbids these cast operations:
Casting from a function pointer to any other type.
Casting from a function pointer to another function pointer, if the function pointers have different arguments and return types.
Polyspace Implementation
Polyspace® raises a violation of this rule if the source type of a cast operation is a pointer to a function.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Expressions |
Category: Required |
Version History
Introduced in R2013b
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.