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. 1
      
         
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_tor- std::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
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.