#if ! SOME_MACROS 等同于 #ifndef SOME_MACROS,如果SOME_MACROS始终具有数值。

huangapple go评论67阅读模式
英文:

#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
}

Link to godbolt

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 &lt;cstdio&gt;

int main() {
    #if !_LIBCPP_VERSION 
        std::printf(&quot;_LIBCPP_VERSION not defined&quot;);
    #else
        std::printf(&quot;_LIBCPP_VERSION defined and equal to %d&quot;, _LIBCPP_VERSION);
    #endif

    #ifndef _LIBCPP_VERSION
        std::printf(&quot;_LIBCPP_VERSION not defined&quot;);

    #else
        std::printf(&quot;_LIBCPP_VERSION defined and equal to %d&quot;, _LIBCPP_VERSION);

    #endif
}

Link to godbolt

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.

huangapple
  • 本文由 发表于 2023年2月9日 02:21:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75390145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定