Linux内核中有如下两个宏:
#define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x) 写代码测试如下:
#include<stdio.h>
#include<stdlib.h>
#define test1 "hello world"
#define test2(x) "hello " #x //hello 后面有一个空格
#define test3(x) "hello "#x //引号和#x之间没有空格
#define test4 "hello" "world" //两个字符串
#define test5(x...) #x
#define test6(x) #x
#define test7(x...) test8(x)
#define test8(a,b) (a+b) #define __stringify_1(x...) #x
#define __stringify(x...) __stringify_1(x)
#define FOO1 BAR1
#define FOO2 BAR2
#define BAR1 AAR1
#define BAR2 AAR2
int main()
{
printf("test1=%s\n",test1);
printf("test2=%s\n",test2( everyone )); //everyone前后有空格
printf("test3=%s\n",test3( everyone test3)); //everyone和test3之间有空格
printf("test4=%s\n",test4);
printf("test5=%s\n",test5(hello world)); //一个参数,hello和world中间有空格
printf("test5=%s\n",test5(hello,world)); //两个参数
printf("test5=%s\n",test5(hello, world)); //,和world之间有空格
printf("test5=%s\n",test5( hello, world )); //hello 前和world后有空格
printf("test5=%s\n",test5( "hello, world" )); //一个参数,但是参数用""引起来了
//printf("%s\n",test6(hello,world)); //编译报错
printf("test6=%s\n",test6(hello world)); //一个参数
printf("test7=%d\n",test7(,)); //两个参数 printf("%s\n",__stringify(FOO1,FOO2)); //两个参数
printf("%s\n",test5(FOO1,FOO2)); //两个参数
return ;
} /*结果如下*/
test1=hello world
test2=hello everyone
test3=hello everyone test3
test4=helloworld
test5=hello world
test5=hello,world
test5=hello, world
test5=hello, world
test5="hello, world"
test6=hello world
test7=
AAR1,AAR2
FOO1,FOO2 /*
结论:
#define DD(x...) x 会将x替换成()里面的内容 例如:DD(1,2)展开就是 1,2
#define DD(x) #x 会将DD(aa)展开成字符串"aa"
#define DD(x...) #x 会将()里面的内容展开成字符串,例如:DD(1,2,3) 展开是”1,2,3"
#define DD "str1" "str2" 会将DD 展开成"str1str2"
所以才有了第55,56,57行的结果,其中第55行和56行对比给出了stringify的用意。
*/

[宏]__stringify的更多相关文章

  1. Linux驱动开发——__stringify

    在Linux内核中有一个宏__stringify,在include/linux/stringify.h定义如下: #ifndef __LINUX_STRINGIFY_H #define __LINUX ...

  2. C++ 中常见预定义宏的使用

    http://blog.csdn.net/hgl868/article/details/7058906 替代字符串: #define DOWNLOAD_IMAGE_LOG /var/log/png.l ...

  3. 宏定义中的##操作符和... and _ _VA_ARGS_ _

    1.Preprocessor Glue: The ## Operator 预处理连接符:##操作符 Like the # operator, the ## operator can be used i ...

  4. MODULE_AUTHOR、MODULE_DESCRIPTION、MODULE_LICENSE宏

    在阅读Linux Driver源码时,我们常常会在文件的结尾处看到诸如:MODULE_AUTHOR.MODULE_DESCRIPTION.MODULE_LICENSE等宏定义,这些宏主要是定义了一些模 ...

  5. Linux驱动中常用的宏

    .module_i2c_driver(adxl34x_driver)展开为 static int __int adxl34x_driver_init(void) { return i2c_regist ...

  6. Linux内核宏DEVICE_ATTR使用

    1.前言 在Linux驱动程序编写中,使用DEVICE_ATTR宏,可以定义一个struct device_attribute设备属性,并使用sysfs的API函数,便可以在设备目录下创建出属性文件, ...

  7. Visual Studio 宏的高级用法

    因为自 Visual Studio 2012 开始,微软已经取消了对宏的支持,所以本篇文章所述内容只适用于 Visual Studio 2010 或更早期版本的 VS. 在上一篇中,我已经介绍了如何编 ...

  8. VC 中与字符串相关的宏 _T、TEXT,_TEXT、L 的作用

    CSDN原博文:http://blog.csdn.net/houkai363/article/details/8134787 遇到了:不能将参数 1 从“const char [5]”转换为“LPCT ...

  9. 【转】linux内核中writesb(), writesw(), writesl() 宏函数

    writesb(), writesw(), writesl() 宏函数 功能 : writesb()    I/O 上写入 8 位数据流数据 (1字节) writesw()   I/O  上写入 16 ...

随机推荐

  1. Python设计模式 - 基础 - 封装 & 继承 & 多态

    面向对象的核心是对象,世间万物都可以看作对象,任何一个对象都可以通过一系列属性和行为来描述,可以包含任意数量和类型的数据或操作.类是用来描述具有相同属性和方法的所有对象的集合.类通常是抽象化的概念,而 ...

  2. Python+Selenium学习--自动化测试模型

    前言 一个自动化测试框架就是一个集成体系,在这一体系中包含测试功能的函数库.测试数据源.测试对象识别标准,以及种可重用的模块.自动化测试框架在发展的过程中经历了几个阶段,模块驱动测试.数据驱动测试.对 ...

  3. vue 根据接口返回的状态码判断用户登录状态并跳转登录页,登录后回到上一个页面(http拦截器)

    背景:后台接口返回code==501表示用户是未登录状态,需要登录才可访问: 通过http拦截做路由跳转 第一步:src目录下新建http.js文件,内容如下: import Axios from ' ...

  4. FortiGate部分用户上网慢,丢包严重

    1.现状: 如图,出口internet有2条联通线路分别为liant_218和liant_61,在防火墙上使用WAN LLB,基于源IP: 2.现象: 使用liant_218的用户上网正常,使用lia ...

  5. Mysql的时间类型问题

    时间类型有time, date, datetime, timestamp 如Mysql官方文档所述: time 没有date,date没有time,datetime是date和time的集合, 而ti ...

  6. C++字符串结束标识

    用一个字符数组可以存放一个字符串中的字符.如: char str[12]={'I',' ','a','m',' ','h','a','p','p','y'}; 用一维字符数组str来存放一个字符串″I ...

  7. [SoapUI] 如何同时调用Global Script Library(放在SoapUI安装目录)和项目特有的Script Libary(放在项目代码下)

    SoapUI 支持引入多个package: Global Script library : 在SoapUI工具File->Preference中设置Project Script Library: ...

  8. JQUERY-定义-查找

    正课: 1. 什么是jQuery 2. 如何使用jQuery 3. 查找 1. 什么是jQuery 第三方开发的 执行DOM操作的 极简化的 函数库 第三方: 下载 执行DOM操作: 学习jQuery ...

  9. 网站日志流量分析采集(LuaJIT系统环境部署-node03,相关jar包自己手动上传)

    注:/usr/local/src 是源码包路径,可以自己更改 服务器中安装依赖 yum -y install gcc perl pcre-devel openssl openssl-devel 上传 ...

  10. SGTtrick

    SGTtrick By 蒟蒻 ldxoiBy\ 蒟蒻\ ldxoiBy 蒟蒻 ldxoi Chapter 1.关于线段树操作的一些分析 我们知道,线段树有两个核心的函数pushdownpushdown ...