【发布时间】:2011-03-07 05:37:49
【问题描述】:
考虑以下代码:
template<bool> class StaticAssert;
template<> class StaticAssert<true> {};
StaticAssert< (-1 < sizeof(int)) > xyz1; // Compile error
StaticAssert< (-1 > sizeof(int)) > xyz2; // OK
为什么-1 > sizeof(int) 是真的?
- 是不是真的
-1被提升为unsigned(-1)然后unsigned(-1) > sizeof(int)。 - 如果 sizeof(int) 为 4,
-1 > sizeof(int)是否等于-1 > size_t(4)。如果是这样,为什么-1 > size_t(4)为 false?
这是符合 C++ 标准的吗?
【问题讨论】:
标签: c++ type-conversion sizeof unsigned modular