<分区>
如下c代码:
#define __xstr(s) __str(s)
#define __str(s) #s
#s 是什么意思?
<分区>
如下c代码:
#define __xstr(s) __str(s)
#define __str(s) #s
#s 是什么意思?
最佳答案
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"
If you want to stringify the expansion of a macro argument, you have to use two levels of macros:
#define xstr(s) str(s)
#define str(s) #s
#define foo 4
str (foo) // outputs "foo"
xstr (foo) // outputs "4"
最后一个示例中的代码与问题中的代码非常接近。请注意,正如 @KeithThompson 提到的,“以两个下划线开头,或一个下划线后跟一个大写字母的标识符是保留的”。
关于c - 下面的c 宏声明是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29900174/