What does the # and ## means in C preprocessor macro of c++
15,306
From the standard (emphasis mine):
16.3.2 The # operator [cpp.stringize]
2/ A character string literal is a string-literal with no prefix. If, in the replacement list, a parameter is immediately preceded by a # preprocessing token, both are replaced by a single character string literal preprocessing token that contains the spelling of the preprocessing token sequence for the corresponding argument. [...]
It "stringifies" the token following the #
.
Example:
#define STRINGIFY(x) #x
STRINGIFY(foo) // will be replaced by "foo"
Author by
user2131316
Updated on June 04, 2022Comments
-
user2131316 almost 2 years
I read the following code:
#define MACRO(abc, def) {#def ## #abc} char result[10] = MARCO(abc, def);
I know the
##
operator is used to merge the two string to one, but what about the#
in front ofdef
andabc
?