0

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • String literal concatenations are covered in the C++ 11 standard, specifically § 2.14.5 [lex.string], paragraph 13. You can read more about it (and a ton more about string literals) in that section. – WhozCraig May 11 '14 at 05:19

1 Answers1

2

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.
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100