[英]Macro Meta Programming
I know this is probably either bad or impossible, but since this isn't a recursive macro I think it should be possible. 我知道这可能是坏的或不可能的,但由于这不是一个递归的宏,我认为它应该是可能的。
#define FOO 15
#define MAKE_BAR(x) BAR_##x
#define MY_FOO_BAR MAKE_BAR(FOO)
I'd like MY_FOO_BAR to evaluate to BAR_15. 我希望MY_FOO_BAR评估为BAR_15。 Is there a way to tell the preprocessor to evaluate FOO before passing it into MAKE_BAR? 有没有办法告诉预处理器在将FOO传递给MAKE_BAR之前对其进行评估?
You need another level of macro calls: 您需要另一级别的宏调用:
#define FOO 15
#define MAKE_BAR_INNER(x) BAR_##x
#define MAKE_BAR(x) MAKE_BAR_INNER(x)
#define MY_FOO_BAR MAKE_BAR(FOO)
This is because of how parameters are handled during functional macro expansion. 这是因为在功能宏扩展期间如何处理参数。 The ##
concatenation operator prevents parameter expansion, so you must "force" expansion by adding another "layer". ##
连接运算符可防止参数扩展,因此必须通过添加另一个“层”来“强制”扩展。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.