Reputation: 339
The #
symbol is used at the start of preprocessor directives (#ifdef
, #define
etc). #
is also used as the stringification operator.
##
is the token pasting operator.
Then in an online quiz I saw this:
#define MAKECHAR(operand) #@operand
What operator is #@
and what is it used for?
Upvotes: 6
Views: 784
Reputation: 35154
It is an analogy to the stringify marker #
but for characters, but it is not standardized. For example, clang/llvm does not support it.
To show the analogy:
#define MESSAGE(x) printf("%s: %d\n", #x, x)
int main(){
int i = 5;
MESSAGE(i); // expands to printf("%s: %d\n", "i", x)
return 0;
}
Output is:
i: 5
With a compiler supporting #@
, you could write:
#define MESSAGE(x) printf("%c: %d\n", #@x, x)
int main(){
int i = 5;
MESSAGE(i); // expands to printf("%c: %d\n", 'i', x)
return 0;
}
Upvotes: 6