什么是#用%s格式时 [英] What is the # for when formatting using %s

查看:114
本文介绍了什么是#用%s格式时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到一个断言的这个例子,想知道是什么是:

 的#define ASSERT(x)如果(!(X)){\\
    为int * p = NULL; \\
    DBGPRINTF(断言失败:[%S] \\ r \\ n停机。#X); \\
    * p值= 1; \\
  }


解决方案

这是stringizepreprocessing运营商。

这需要作为参数传递给宏参数 X 通过令牌并将其转换为一个字符串。

 的#define ASSERT(X)#XASSERT(A B C D)
//被替换
A B C D

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; \
  } 

解决方案

It is the "stringize" preprocessing operator.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆