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. centos下通过pid查看进程的绝对路径的方法

    例如: 我想要知道我执行中的mysql路径 netstat -nlp pid拿到15330,然后 cd /proc/15330 由于linux在启动一个进程时,会在/proc下创建一个以PID命名的文 ...

  2. GPL_LGPL

    LGPL 与GPL的区别   GPL(GNU General Public License) 我们很熟悉的Linux就是采用了GPL.GPL协议和BSD, Apache Licence等鼓励代码重用的 ...

  3. 259. 3Sum Smaller小于版3sum

    [抄题]: Given an array of n integers nums and a target, find the number of index triplets i, j, k with ...

  4. JavaSE基础知识(5)—面向对象(5.2类的成员)

    一.属性 1.语法 数据类型 属性名 [= 属性值]; 2.特点 ①属性的数据类型可以为任意类型,包含基本类型或引用类型②属性可以不用手动赋值,有默认值 int——0 double——0.0 char ...

  5. linux下apt安装mysql导致mysql.user table is damaged

    笔者在ubuntu下用 apt install mysql-server类似的命令安装mysql, 安装了最新版的mysql5.7,覆盖了操作系统内置的数据库mysql系统库. 最初启动mysql出错 ...

  6. Admin注册和路由分发详解

    Admin注册和路由分发详解 1.启动 #autodiscover_modules('admin', register_to=site) 2.注册 1.单例对象 admin.site = AdminS ...

  7. VS2015 提示 无法启动 IIS Express Web 服务器

    好久没有写东西了,不是没的写,是没时间了,今天快下班了,正好遇到这个一个问题,我就记录下来,以防忘记. 我定义了一个项目,Demo代码也写好了,然后,我们就把写好的项目代码加入到了源代码管理工具里.然 ...

  8. VS中程序包错误,引用错误该如何解决

    1.找到包的文件.packages.config 对应于: 2.删除掉 packages.config 报错的项.然后再重新添加一次.就没有解决的不了的问题. 是不是很爽.....

  9. spring入门--spring入门案例

    spring是一个框架,这个框架可以干很多很多的事情.感觉特别吊.但是,对于初学者来说,很难理解spring到底是干什么的.我刚开始的时候也不懂,后来就跟着敲,在后来虽然懂了,但是依然说不明白它到底是 ...

  10. maven 项目中没有src/test/java文件夹

    项目右键->buildPath configure Build Path->点击选项卡Libraries->选中JRE System Library->点击edit->选 ...