使用%s格式化时的#是什么 [英] What is the # for when formatting using %s
本文介绍了使用%s格式化时的#是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了这个断言的例子,想知道#
是用于:
I came across this example of an assertion and was wondering what the #
is for:
#define ASSERT( x ) if ( !( x ) ) { \
int *p = NULL; \
DBGPRINTF("Assert failed: [%s]\r\n Halting.", #x); \
*p=1; \
}
推荐答案
stringize预处理操作符。
It is the "stringize" preprocessing operator.
它将作为参数传递给宏参数 x
的令牌转换为字符串文字。 / p>
It takes the tokens passed as the argument to the macro parameter x
and turns them into a string literal.
#define ASSERT(x) #x
ASSERT(a b c d)
// is replaced by
"a b c d"
这篇关于使用%s格式化时的#是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文