英文:
#if ! SOME_MACROS equivalent with #ifndef SOME_MACROS if SOME_MACROS always has numerical value
问题
以下是您要翻译的部分:
"May be this is duplicate, I can't find similar question.
My surprise that, following code works for all three big compiler without error
#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
}
My question is that: There check #if !_LIBCPP_VERSION
- is always similar with #ifndef _LIBCPP_VERSION
by standard C or C++?"
英文:
May be this is duplicate, I can't find similar question.
My surprise that, following code works for all three big compiler without error
#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
}
My question is that: There check #if !_LIBCPP_VERSION
- is always similar with #ifndef _LIBCPP_VERSION
by standard C or C++?
答案1
得分: 2
它们在数值上不等同。
SOME_MACROS |
#if !SOME_MACROS |
#ifndef SOME_MACROS |
---|---|---|
x |
True | False |
1 |
False | False |
0 |
True | False |
undef | True | True |
现在,你说你只关心数值,所以这里只有中间的行是相关的。然而,我们在这两行中看到了一个差异。
英文:
They are not equivalent for numerical values.
SOME_MACROS |
#if !SOME_MACROS |
#ifndef SOME_MACROS |
---|---|---|
x |
True | False |
1 |
False | False |
0 |
True | False |
undef | True | True |
Now, you said you only care about numerical values, so only the middle rows are relevant here. Yet we see a difference in those two rows.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论