简体   繁体   English

调用没有括号的类似函数的宏吗?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM