gpt4 book ai didi

c - 预处理指令之前的空宏的标准行为

转载 作者:太空宇宙 更新时间:2023-11-04 07:51:46 24 4
gpt4 key购买 nike

举个例子:

#define FOO
FOO #define BAR 1
BAR

根据 ANSI C 和 C99 标准,上述代码的预处理输出应该是什么?

在我看来,这应该被评估为1;但是,通过 gcc -Eclang -E 运行上面的示例会产生以下结果:

    #define BAR 1
BAR

最佳答案

标准草案“ISO/IEC 9899:201x 委员会草案 — 2011 年 4 月 12 日 N1570”第 6.10 节实际上包含一个示例:

EXAMPLE In:

#define EMPTY 
EMPTY # include <file.h>

the sequence of preprocessing tokens on the second line is not a preprocessing directive, because it does not begin with a # at the start of translation phase 4, even though it will do so after the macro EMPTY has been replaced.

它告诉我们“...第二行不是预处理指令...”

所以对于你的代码

FOO #define BAR 1

不是预处理指令,这意味着只有 FOO 将被替换,而 BAR 将被定义。因此预处理器的输出是:

 #define BAR 1
BAR

关于c - 预处理指令之前的空宏的标准行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53358884/

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