我想知道是否可以使用 gcc 输出“预处理”代码但“忽略”(不扩展)包括:
ES 我得到了这个主要的:
#include <stdio.h>
#define prn(s) printf("this is a macro for printing a string: %s\n", s);
int int(){
char str[5] = "test";
prn(str);
return 0;
}
我运行 gcc -E main -o out.c
我得到了:
/*
all stdio stuff
*/
int int(){
char str[5] = "test";
printf("this is a macro for printing a string: %s\n", str);
return 0;
}
我只想输出:
#include <stdio.h>
int int(){
char str[5] = "test";
printf("this is a macro for printing a string: %s\n", str);
return 0;
}
或者,至少,只是
int int(){
char str[5] = "test";
printf("this is a macro for printing a string: %s\n", str);
return 0;
}
PS:如果可能扩展“本地”会很棒""
包括但不展开“全局”<>
包括
最佳答案
我同意 Matteo Italia 的评论,如果你只是阻止 #include
指令被扩展,那么生成的代码将不会代表编译器实际看到的内容,因此它会受到限制用于故障排除。
这里有一个解决这个问题的想法。在包含之前和之后添加变量声明。任何合理唯一的变量都可以。
int begin_includes_tag;
#include <stdio.h>
... other includes
int end_includes_tag;
然后你可以这样做:
> gcc -E main -o out.c | sed '/begin_includes_tag/,/end_includes_tag/d'
sed
命令将删除这些变量声明之间的所有内容。
关于c - 如何显示 'preprocessed' 代码忽略包括 GCC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54891248/