可能这是重复的,我找不到类似的问题。
令我惊讶的是,以下代码适用于所有三大编译器,没有错误
#include <cstdio>
int main() {
#if !_LIBCPP_VERSION
std::printf("_LIBCPP_VERSION not defined");
#else
std::printf("_LIBCPP_VERSION defined and equal to %d", _LIBCPP_VERSION);
#endif
#ifndef _LIBCPP_VERSION
std::printf("_LIBCPP_VERSION not defined");
#else
std::printf("_LIBCPP_VERSION defined and equal to %d", _LIBCPP_VERSION);
#endif
}
我的问题是:有检查
#if !_LIBCPP_VERSION
- 总是与标准 C 或 C++ 的 #ifndef _LIBCPP_VERSION
类似吗?
它们对于数值而言并不等价。
|
|
|
---|---|---|
|
正确 | 错误 |
|
错误 | 错误 |
|
正确 | 错误 |
未定义 | 正确 | 正确 |
现在,您说您只关心数值,因此这里只有中间行相关。然而我们看到这两行存在差异。