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. day36 GIL锁与线程池

    多进程与多线程效率对比 # # """ # # 计算密集型 # """ # from threading import Thread # f ...

  2. 【python深入】装饰器理解及使用

    装饰器,其实就是一个函数,它可以让其他函数在不需要做任何代码变动的前提下额外增加功能,装饰器的返回是一个函数对象. 用一个例子来说明一下什么是函数对象: 从这里可以看到,直接在函数后面加bar(),就 ...

  3. Eclipse设置智能提示

    1.解决智能感知提示响应时间,使Eclipse追上VS的响应步伐:Window→Preferences→Java→Editor→Content Assist 这里的Auto activation de ...

  4. jfinal处理完html提交过来的数据,将处理信息返回给html页面。html根据返回值进行相应的处理

    1.前台jQuery代码: $.ajax({ url: "/admin/jcsjpz/syxmdy/RemoveSyxm", data: {data: id}, success: ...

  5. Nodejs初识随笔

    Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境. Node.js 使用了一个事件驱动.非阻塞式 I/O 的模型,使其轻量又高效. Node.js 单线程运行,不 ...

  6. Step by Step Guide on Yanhua ACDP Clear BMW EGS ISN

    Yanhua Mini ACDP authorize new function on BMW EGS ISN clearing.So here UOBDII want to share this st ...

  7. Julia 下载 安装 juno 开发环境搭建

    Windows平台 Julia 的官网 (https://julialang.org) 下载链接(https://julialang.org/downloads) 下载完成后,如果想安装在 C 盘,则 ...

  8. IFrame跨域访问&&IFrame跨域访问自定义高度

    1.IFrame跨域访问: http://blog.csdn.net/fdipzone/article/details/17619673 2.IFrame跨域访问自定义高度: 由于JS禁止跨域访问,如 ...

  9. C++ 提取网页内容系列之三

    标 题: C++ 提取网页内容系列作 者: itdef链 接: http://www.cnblogs.com/itdef/p/4171659.html 欢迎转帖 请保持文本完整并注明出处 这次继续下载 ...

  10. Html5学习笔记:图片上传

    图片上传是业务需求中常见的功能,最基础的是单图片的上传.比较复杂的多图片上传,都是基于单图片上传. Form表单上传 h5的原生表单上传图片,代码如下: <!DOCTYPE html> & ...