DDS*_*DDS 4 c linux gcc c-preprocessor
我想知道是否可以使用 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;
}
Run Code Online (Sandbox Code Playgroud)
我跑 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;
}
Run Code Online (Sandbox Code Playgroud)
我只想输出:
#include <stdio.h>
int int(){
char str[5] = "test";
printf("this is a macro for printing a string: %s\n", str);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
或者,至少,只是
int int(){
char str[5] = "test";
printf("this is a macro for printing a string: %s\n", str);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
PS:如果可能的话扩展“本地”""包含而不扩展“全局”<>包含会很棒
我同意 Matteo Italia 的评论,如果你只是阻止 #include指令被扩展,那么生成的代码将不会代表编译器实际看到的内容,因此它在故障排除中的用途有限。
这里有一个想法来解决这个问题。在包含之前和之后添加变量声明。任何合理唯一的变量都可以。
int begin_includes_tag;
#include <stdio.h>
... other includes
int end_includes_tag;
Run Code Online (Sandbox Code Playgroud)
然后你可以这样做:
> gcc -E main -o out.c | sed '/begin_includes_tag/,/end_includes_tag/d'
Run Code Online (Sandbox Code Playgroud)
该sed命令将删除这些变量声明之间的所有内容。
| 归档时间: |
|
| 查看次数: |
1916 次 |
| 最近记录: |