GCC使用-D参数定义类似函数的宏

Ste*_*aly 10 c macros gcc command-line-arguments c-preprocessor

问题

我在尝试将其发送到解析器之前__attribute__从我的C代码中删除.有没有办法使用-D参数定义类似函数的宏?

解决方案使用头文件

#define __attribute__(x)
Run Code Online (Sandbox Code Playgroud)

试图解决方案

gcc -E -D__attribute__(x)= testfile.c
gcc -E -D__attribute__(x) testfile.c
Run Code Online (Sandbox Code Playgroud)

Rob*_*obs 16

从手册页

       If you wish to define a function-like macro on the command line,
       write its argument list with surrounding parentheses before the
       equals sign (if any).  Parentheses are meaningful to most shells,
       so you will need to quote the option.  With sh and csh,
       -D'name(args...)=definition' works.
Run Code Online (Sandbox Code Playgroud)

所以这适用于Unix/Linux shell

gcc -D'__attribute__(x)='
Run Code Online (Sandbox Code Playgroud)

在Windows CMD上,原始表达式有效,因为括号不是特殊的:

gcc -D__attribute__(x)=
Run Code Online (Sandbox Code Playgroud)