我想要做这样的事情:
#define __attribute__((aligned(2))) __attribute__((space(prog),aligned(2)))
但编译器给出的结果是:
error: "(" may not appear in macro parameter list
问题:怎样进行字面文本替换,不要有任何修饰或附加条件?
我想要做这样的事情:
#define __attribute__((aligned(2))) __attribute__((space(prog),aligned(2)))
error: "(" may not appear in macro parameter list
问题:怎样进行字面文本替换,不要有任何修饰或附加条件?
#define succ(x) (x + 1)
但你不能做到:
#define pred(x + 1) x
预处理器只能进行非常有限的模式匹配。
相反,您可以尝试以下方法:
#define __aligned2__ __attribute__((space(prog),aligned(2)))
使用该定义即可。如果您的需求不足,您需要使用 sed
进行一些自定义预处理。
__attribute__
结构包装在对象式宏中来解决此问题:#if appropriate condition
#define ATTRIBUTE_ALIGNED_2 __attribute__((space(prog),aligned(2)))
#else
#define ATTRIBUTE_ALIGNED_2 __attribute__((aligned(2)))
#endif
然后在整个源代码中将__attribute__((aligned(2)))
替换为ATTRIBUTE_ALIGNED_2
。
__attribute__((noreturn))
,就会出现问题。 - zwolsed
、Perl或其他方便的工具。这样比C预处理器让你做的更加灵活。 - zwol
#define __attribute__((aligned(2))) __attribute__((space(prog),aligned(2)))
? - Benjamin Bannier