【发布时间】:2015-10-29 16:59:19
【问题描述】:
问题
我正在尝试从 C 代码中删除 __attribute__,然后再将其发送到解析器。有没有办法使用-D 参数定义类似函数的宏?
使用头文件的解决方案
#define __attribute__(x)
尝试的解决方案
gcc -E -D__attribute__(x)= testfile.c
gcc -E -D__attribute__(x) testfile.c
【问题讨论】:
-
你试过
gcc -E -D'__attribute__(x)' testfile.c吗?您的 shell 可能会在将参数发送到gcc之前解释括号。 -
@NiBZ 对不起,不担心。回来说“宏名必须是标识符”
-
奇怪,它对我有用(Ubuntu 14.04)...(有关我测试的内容,请参阅 gist.github.com/N-Bz/dff2706c2ccec97d9542)。如果头文件解决方案有效,那么
gcc的-include选项(强制包含头文件)可能会对您有所帮助。 -
gcc -E -D__attribute__(x)= testfile.c适用于 Windows。
标签: c gcc macros command-line-arguments c-preprocessor