gpt4 book ai didi

c - 在两个源文件之间拆分类似函数的宏调用

转载 作者:行者123 更新时间:2023-12-05 09:03:16 25 4
gpt4 key购买 nike

C 标准中是否有任何内容阻止我执行以下操作?

// main.c
#define DECORATE(x) ***x***
#include "call_macro.h"
this is the text I want decorated)
// call_macro.h
DECORATE(

当通过 gcc -E main.c 运行它时,我希望得到

*** this is the text I want decorated***

相反,它提示 macro_call.h:2: error: unterminated argument list invoking macro "DECORATE",但实际上我在标准中找不到任何对它的禁止。

想法?

最佳答案

5.1.1.2 Translation phases
(1.4) Preprocessing directives are executed, macro invocations are expanded, and _Pragma unary operator expressions are executed... A #include preprocessing directive causes the named header or source file to be processed from phase 1through phase 4, recursively. All preprocessing directives are then deleted.

我相信这表明每个包含的 header 在“合并”到整个翻译单元之前都经过单独预处理。正是在这一点上,不完整的类似函数的宏调用将是格式错误的:

6.10.3/4 ... There shall exist a ) preprocessing token that terminates the invocation.

关于c - 在两个源文件之间拆分类似函数的宏调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70136145/

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