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

问题描述

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


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

编辑:

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


解决方案

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 ##是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 12:49