1

What does it mean in C : #define ABC(a,b) {#a, a, b} ?

I understand that ABC is a Macro with parameters (a,b).

But what does it mean {#a, a, b} and especially what does mean "#a" in such case?

Sunkat
  • 393
  • 1
  • 3
  • 8

1 Answers1

2

This is used to do stringification. From manual.

Sometimes you may want to convert a macro argument into a string constant. Parameters are not replaced inside string constants, but you can use the # preprocessing operator instead. When a macro parameter is used with a leading #, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant. Unlike normal parameter replacement, the argument is not macro-expanded first. This is called stringification.

There is an example in the manual itself which clears the idea.

#define WARN_IF(EXP) \
do { if (EXP) \
        fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
WARN_IF (x == 0);
 (expanded to)==> do { if (x == 0)
           fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0);
user2736738
  • 30,591
  • 5
  • 42
  • 56