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

GCC define function-like macros using -D argument

问题

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

使用头文件的解决方案

#define __attribute__(x)

尝试的解决方案

gcc -E -D__attribute__(x)= testfile.c
gcc -E -D__attribute__(x) testfile.c

来自手册页

       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.

所以这适用于 Unix/Linux shell

gcc -D'__attribute__(x)='

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

gcc -D__attribute__(x)=