考虑这个(可怕的,可怕的,没有好的,非常糟糕的)代码结构:
#define foo(x) // commented out debugging code
// Misformatted to not obscure the point
if (a)
foo(a);
bar(a);
Run Code Online (Sandbox Code Playgroud)
我已经看到两个编译器的预处理器在这段代码上生成不同的结果:
if (a)
bar(a);
Run Code Online (Sandbox Code Playgroud)
和
if (a)
;
bar(a);
Run Code Online (Sandbox Code Playgroud)
显然,对于可移植的代码库来说这是一件坏事.
我的问题:预处理器应该用这个做什么?首先是Elide评论,还是先扩展宏?
有没有人引用海报/单页pdf或类似的东西与C语言的八个翻译阶段列表(第一个是三字母翻译)?我想在我的电脑旁边的墙上挂一个印刷品.
更新:抱歉忘记指定.我对C90很感兴趣(虽然C99可能非常接近,_Pragma如pmg所说,答案是C99特定的,我想避免这种情况).