MISRAC++2023-8.2.8 (C++ only)
In this section:
Synopsis
(Required) An object pointer type shall not be cast to an integral type other than std::uintptr_t or std:intptr_t
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Use designated standard types as these are the only types guaranteed to represent all possible object pointer values
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
#include <cstdint>
struct S;
void example( S* s ) {
auto p1 = reinterpret_cast< unsigned long >( s ); // Non-compliant
}
The following code example passes the check and will not give a warning about this issue:
#include <cstdint>
struct S;
void example(S* s) {
auto p0 = reinterpret_cast< std::uintptr_t >( s ); // Compliant
}