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?
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);