[英]Calling a function-like macro without parentheses?
Suppose that we pass the following to the gcc
's preprocessor: 假设我们将以下内容传递给
gcc
的预处理器:
#define REM(...) __VA_ARGS__
#define PAIR(x) REM x
PAIR((a)b)
It expands PAIR((a)b)
into ab
. 它将
PAIR((a)b)
扩展为ab
。 How does this happen? 这是怎么发生的? I am confused about
REM
being used without parentheses and x
not being echoed as is... 我对
REM
没有括号且x
没有按原样回显感到困惑...
When you write: 当你写:
PAIR((a)b)
given the definition 给定定义
PAIR(x) REM x
that means x = (a)b
. 这意味着x =
(a)b
。 So, we can write out the right hand side as 因此,我们可以写出右侧为
REM (a)b
right? 对?
Now REM(a)
is just a
, so REM (a)b
is just ab
(tokens are separated by whitespace unless you explicitly use token pasting). 现在
REM(a)
只是a
,所以REM (a)b
只是ab
(令牌由空格分隔,除非您明确使用令牌粘贴)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.