1

What does the # before s mean in the following snippet? I am not referring to the # before define or the ones used for preprocessor directives.

// Quote a given token stream to turn it into a string.
#define DEV_QUOTED_HELPER(s) #s
#define DEV_QUOTED(s) DEV_QUOTED_HELPER(s)

This question is different from "Stringification - how does it work?" because someone having this question doesn't know the term 'stringification'. It is different from "What is '#' operator in C?" because it appears in C++ code too and in such cases even SO fails to show this question in the list of similar questions(it showed other possible questions in SQL, python etc).

user3740387
  • 337
  • 1
  • 3
  • 13

1 Answers1

5

Taken from https://en.wikipedia.org/wiki/C_preprocessor:

The # operator (known as the "Stringification Operator") converts a token into a string, escaping any quotes or backslashes appropriately.

Example:

#define str(s) #s

str(p = "foo\n";) // outputs "p = \"foo\\n\";"
str(\n)           // outputs "\n"
JJJ
  • 32,902
  • 20
  • 89
  • 102
OriBS
  • 722
  • 5
  • 9