Strange macro macro syntax (#var)

What does the # symbol mean when using a variable in the #define macro as a prefix?

For example,

#define my_setopt(x,y,z) _my_setopt(x, 0, config, #y, y, z)
+3
source share
2 answers

This is a Stringizing Operator that converts macro parameters to string literals.

So in your example:

my_setopt(1, 2, 3)

will expand to:

_my_setopt(1, 0, config, "2", 2, 3)
+7
source

#quotes the expression. For example:

#define SHOW(BAR) printf("%s is %d\n", #BAR , BAR)
SHOW(3+5);  // prints: 3+5 is 8
+2
source

Source: https://habr.com/ru/post/1716506/


All Articles