相关疑难解决方法(0)

C预处理器是否首先删除注释或扩展宏?

考虑这个(可怕的,可怕的,没有好的,非常糟糕的)代码结构:

#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评论,还是先扩展宏?

c comments c99 c-preprocessor

54
推荐指数
3
解决办法
2万
查看次数

是否始终在预处理器之前处理注释?

/*
#define FOO
*/

#ifdef FOO
#define BAR "pirate"
#else
#define BAR "ninja"
#endif

int main() { printf(BAR); getchar(); }
Run Code Online (Sandbox Code Playgroud)

在此代码中,未定义FOO(Visual Studio 2008).我假设首先处理注释,然后是预处理器,然后是代码.是否始终在预处理器之前处理注释?这是标准的一部分吗?

c comments c-preprocessor

5
推荐指数
3
解决办法
2022
查看次数

编译时c中的注释被删除了吗?

ac 源文件中的注释是否被编译器删除(例如 Visual C++ 和 GCC)?

/* ... */

// ...
Run Code Online (Sandbox Code Playgroud)

c compiler-construction comments

2
推荐指数
1
解决办法
1575
查看次数

标签 统计

c ×3

comments ×3

c-preprocessor ×2

c99 ×1

compiler-construction ×1