gpt4 book ai didi

C 拼图 {MACRO}

转载 作者:行者123 更新时间:2023-12-04 11:38:59 26 4
gpt4 key购买 nike

我在某处遇到了以下难题

#include <stdio.h>
int main()
{
{

/*Fill in something here to make this code compile
...........
*/
ooOoO+=a;
}
#undef ooOoO
printf("%d",ooOoO);

return 0;
}

简而言之,我想问一下如何在 #undef ed 之后在 printf 中使用 ooOoO

最佳答案

您需要将其声明为变量:

#define ooOoO int ooOoO = 42; int a = 1; { ooOoO

宏替换是非递归的;当 ooOoO 被替换时,标识符 ooOoO 将不会被视为宏名称。


如果您正在寻找一种使用宏的解决方案,那么您可以简单地忽略#undef 指令并且从不声明ooOoO 作为宏。在 C 和 C++ 中都允许 #undef 未定义为宏的标识符。

关于C 拼图 {MACRO},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4961041/

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