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.
##
is called token concatenation, used to concatenate two tokens in a macro invocation.
See this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With