我正在尝试声明一个初始化为某个常量整数值的 constexpr 指针,但是 clang 正在挫败我的所有尝试:
尝试1:
constexpr int* x = reinterpret_cast<int*>(0xFF);
test.cpp:1:20: note: reinterpret_cast is not allowed in a constant expression
尝试2:
constexpr int* x = (int*)0xFF;
test.cpp:1:20: note: cast which performs the conversions of a reinterpret_cast is not allowed in a constant expression
尝试 3:
constexpr int* x = (int*)0 + 0xFF;
test.cpp:1:28: note: cannot perform pointer arithmetic on null pointer
我试图做的事情是设计不允许的吗?如果是这样,为什么?如果没有,我该怎么做?
注意:gcc 接受所有这些。