是什么在的#define ##是什么意思? [英] What does ## in a #define mean?

查看:281
本文介绍了是什么在的#define ##是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么意思行?特别是,什么是 ## 意思?


#定义ANALYZE(可变,旗)((有什么。##变)(标志))

编辑:

一个有点困惑依然。将结果是什么,而不 ##


解决方案

  

一个有点困惑依然。将结果是没有什么##?


通常你不会注意到任何区别。但是,是的区别。假设的东西的类型是:

 结构X {INT X; };
点¯x的东西;

和查看:

  INT X :: * p =&放大器; X :: X;
ANALYZE(X,旗)
ANALYZE(* P,旗)

无标记连接符 ## ,它扩展为:

 的#define ANALYZE(可变,旗)((Something.variable)及(标志))((有什么X)安培;(标志))
((有什么*ρ)及(标志))//。和*不连接起来以一个令牌。语法错误!

使用令牌串联它扩展为:

 的#define ANALYZE(可变,旗)((##东西可变)及(标志))((Something.x)及(标志))
(。(有什么* P)及(标志))// *是新生成的令牌,现在的作品!

要记住,preprocessor上preprocessor令牌的不可以上的文字工作是很重要的。所以,如果你想连接两个标记,你必须明确地说出来。

What does this line mean? Especially, what does ## mean?

#define ANALYZE(variable, flag)     ((Something.##variable) & (flag))

Edit:

A little bit confused still. What will the result be without ##?

解决方案

A little bit confused still. What will the result be without ##?

Usually you won't notice any difference. But there is a difference. Suppose that Something is of type:

struct X { int x; };
X Something;

And look at:

int X::*p = &X::x;
ANALYZE(x, flag)
ANALYZE(*p, flag)

Without token concatenation operator ##, it expands to:

#define ANALYZE(variable, flag)     ((Something.variable) & (flag))

((Something. x) & (flag))
((Something. *p) & (flag)) // . and * are not concatenated to one token. syntax error!

With token concatenation it expands to:

#define ANALYZE(variable, flag)     ((Something.##variable) & (flag))

((Something.x) & (flag))
((Something.*p) & (flag)) // .* is a newly generated token, now it works!

It's important to remember that the preprocessor operates on preprocessor tokens, not on text. So if you want to concatenate two tokens, you must explicitly say it.

这篇关于是什么在的#define ##是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆