MISRA C++:2023 Rule 8.2.8
An object pointer type shall not be cast to an integral type other than
std::uintptr_t
or std::intptr_t
Since R2024b
Description
Rule Definition
An object pointer type shall not be cast to an integral type other than
std::uintptr_t
or std::intptr_t
.
Rationale
The C++ standard guarantees that the types std::uintptr_t
and
std::intptr_t
accommodate all possible values of a pointer. Other
integral types cannot accommodate all possible values of a pointer. Casting a pointer to
an integral type other than std::uintptr_t
or
std::intptr_t
can result in unexpected behavior.
To comply with this rule, use the type std::uintptr_t
or
std::intptr_t
in the cast expression explicitly.
Polyspace Implementation
Polyspace® reports a violation of this rule if both of these conditions are true:
You cast a pointer to an integral type, either using a cast operator or by using C-style casts.
The cast expression does not explicitly use the types
std::uintptr_t
orstd::intptr_t
.
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 R2024b