[英]Strange Macro Expansion
I recently came across this macro: 我最近遇到过这个宏:
#define EAT(...)
#define STRIP(x) EAT x
STRIP( (1) 2 ) \\ expands to 2
Now can someone please explain what is going on? 现在有人可以解释一下发生了什么吗?
How this EAT x expands? 这个EAT x如何扩展?
What that parenthesis'(1)' do? 括号'(1)'的作用是什么?
Why I can´t do the reverse like STRIP( 1 (2) ) ? 为什么我不能像STRIP(1(2))那样反向?
My initial intentions was spliting one argument in a macro like SPLIT(1 2) to expands to 1,2 there is a way? 我最初的意图是在像SPLIT(1 2)这样的宏中将一个参数拆分为扩展到1,2有一种方法吗?
EAT
is a function-like macro, which means it must be used like EAT(something)
, and it expands to nothing. EAT
是一个类似函数的宏,这意味着它必须像EAT(something)
一样使用,并且它会扩展为空。
So STRIP((1) 2)
expands to EAT (1) 2
which expands to 2
所以
STRIP((1) 2)
扩展到EAT (1) 2
,扩展到2
What that parenthesis'(1)' do?
括号'(1)'的作用是什么?
it forms EAT(1)
which gets expanded 它形成了扩展的
EAT(1)
Why I can´t do the reverse like STRIP( 1 (2) ) ?
为什么我不能像STRIP(1(2))那样反向?
because that forms EAT 1 (2)
and you can't use EAT
like that. 因为那形成了
EAT 1 (2)
,你不能像那样使用EAT
。
Lets step through the substitutions: 让我们逐步完成替换:
STRIP( (1) 2 )
EAT (1) 2
2
For the second example: 对于第二个例子:
STRIP( 1 (2) )
EAT 1 (2)
//error, EAT is a macro so it needs ()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.