In C++ how can I get the integral representation of a pointer at compile time?
#include <bit>
constexpr int x = 5;
constexpr auto y = &x;
int main() {
// The following does not work since it is forbidden for pointers!
constexpr auto i = std::bit_cast<uintptr_t>(y);
return 0;
}
Is there any hack to achieve this in C++20?
Any hidden compiler intrinsic or __builtin
function?
I'm targetting Clang, GCC and MSVC.