Stringification in C involves more than putting double-quote characters around the fragment.
The preprocessor backslash-escapes the quotes surrounding embedded string constants, and all backslashes within string and character constants, in order to get a valid C string constant with the proper contents.
Thus, stringifying p = "foo\n"; results in "p = \"foo\\n\";". However,
backslashes that are not inside string or character constants are not duplicated: ‘\n’ by itself stringifies to "\n".
实验如下:
stringification.c
#include <unistd.h>
#include <stdio.h>
#define WARN(EXP) fprintf (stderr, "Warning: " #EXP "\n");
int main(void)
{
WARN(p= "foo\n");
return 0;
}
gcc constptr.c -E stringification.c -o stringification.i
stringification.i
int main(void)
{
fprintf (stderr, "Warning: " "p= \"foo\\n\"" "\n");;
return 0;
}
-------------------------------------------------------------------------------------------------
后续实验的结果:
实参 :“p= foo\n" 预处理后 "\"p= foo\\n\""
实参:”\n“ 预处理后 "\"\\n\""
实参 : \n 预处理后 "\n"
实参 :' \n' 预处理后 "'\\n'"