Search code examples
c++c-preprocessorstringification

What happens when the preprocessor sees SLOT(a) "1"#a


My understanding is the preprocessor #define replaces identifier with replacement

#define <identifier> <replacement>

Let's suppose we have the following:

#define SLOT(a) "1"#a

void myValue(int value);
SLOT(myValue(int));

I understand that # means take the string literal. Thus, after the macro, wouldn't we have

"1""myValue(int)"

... essentially two string literals back to back. I am guessing the preprocessor automatically concatenates two string literals back to back. Is this true? Where can I find information on this fact?


Solution

  • Yes your understanding is right.

    1. # operator is stringizer operator.
    2. Two string literals one after another separated by 0 or more white space characters are concatenated into single string literal.