gpt4 book ai didi

c - 预处理器和宏

转载 作者:行者123 更新时间:2023-11-30 19:29:21 25 4
gpt4 key购买 nike

#include <stdio.h>
#define macro(n, a, i, m) m##a##i##n
#define MAIN macro(n, a, i, m)
int MAIN()
{

printf("GeeksQuiz");

return 0;
}

大家好在这个问题中,输出是 geeksquiz,因为它说 main 首先被宏替换,然后再次替换。实际更换在哪里进行?不就是定义函数吗?谢谢您

最佳答案

这发生在编译器翻译的第四阶段(称为预处理阶段)。

您可以阅读“Phases of Translation

If there was some other name of the function other than macro , would it have done the same or defined it as different functions

是的。 “宏”可以更改为其他名称。

#define some_other_name(n, a, i, m) m##a##i##n
#define MAIN some_other_name(n, a, i, m)

How do we know when the main function is getting replaced. In cases ive seen that they are defined as separate functions, is it due to macro or MAIN ? ( Sorry new to C here )

因为 MAIN 被定义为 MACRO,并且 MACRO 扩展导致 main

关于c - 预处理器和宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52922870/

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