gpt4 book ai didi

c++ - if-指令宏比较

转载 作者:行者123 更新时间:2023-12-01 08:41:23 25 4
gpt4 key购买 nike

为什么是#if满足以下代码中的条件:

#include <iostream>
#define VALUE foo

int main() {
#if VALUE == bar
std::cout << "WORKS!" << std::endl;
#endif // VALUE
}

最佳答案

page on cppreference.com状态:

After all macro expansion and evaluation of defined and __has_include (since C++17) expressions, any identifier which is not a boolean literal is replaced with the number ​0​ (this includes identifiers that are lexically keywords, but not alternative tokens like and).



所以 VALUE首先替换为 foo ,然后都是 foobar替换为 0。

关于c++ - if-指令宏比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60779032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com