[宏]__stringify
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的更多相关文章
- Linux驱动开发——__stringify
在Linux内核中有一个宏__stringify,在include/linux/stringify.h定义如下: #ifndef __LINUX_STRINGIFY_H #define __LINUX ...
- C++ 中常见预定义宏的使用
http://blog.csdn.net/hgl868/article/details/7058906 替代字符串: #define DOWNLOAD_IMAGE_LOG /var/log/png.l ...
- 宏定义中的##操作符和... and _ _VA_ARGS_ _
1.Preprocessor Glue: The ## Operator 预处理连接符:##操作符 Like the # operator, the ## operator can be used i ...
- MODULE_AUTHOR、MODULE_DESCRIPTION、MODULE_LICENSE宏
在阅读Linux Driver源码时,我们常常会在文件的结尾处看到诸如:MODULE_AUTHOR.MODULE_DESCRIPTION.MODULE_LICENSE等宏定义,这些宏主要是定义了一些模 ...
- Linux驱动中常用的宏
.module_i2c_driver(adxl34x_driver)展开为 static int __int adxl34x_driver_init(void) { return i2c_regist ...
- Linux内核宏DEVICE_ATTR使用
1.前言 在Linux驱动程序编写中,使用DEVICE_ATTR宏,可以定义一个struct device_attribute设备属性,并使用sysfs的API函数,便可以在设备目录下创建出属性文件, ...
- Visual Studio 宏的高级用法
因为自 Visual Studio 2012 开始,微软已经取消了对宏的支持,所以本篇文章所述内容只适用于 Visual Studio 2010 或更早期版本的 VS. 在上一篇中,我已经介绍了如何编 ...
- VC 中与字符串相关的宏 _T、TEXT,_TEXT、L 的作用
CSDN原博文:http://blog.csdn.net/houkai363/article/details/8134787 遇到了:不能将参数 1 从“const char [5]”转换为“LPCT ...
- 【转】linux内核中writesb(), writesw(), writesl() 宏函数
writesb(), writesw(), writesl() 宏函数 功能 : writesb() I/O 上写入 8 位数据流数据 (1字节) writesw() I/O 上写入 16 ...
随机推荐
- [leetcode]57. Insert Interval插入区间
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...
- RHCS(概念篇)
一. 什么是RHCS RHCS是Red Hat Cluster Suite的缩写,也就是红帽子集群套件,RHCS是一个能够提供高可用性.高可靠性.负载均衡.存储共享且经济廉价的集群工具集合,它将集群系 ...
- Django-ConttentType
一 content-type 在django中,有一个记录了项目中所有model元数据的表,就是ContentType,表中一条记录对应着一个存在的model,所以可以通过一个ContentType表 ...
- MySQL开发——【高级操作、五子句】
高级新增操作 ①基本插入操作: insert into 数据表名称(字段) values (值); ②批量插入操作: insert into 数据表名称(字段) values (值1),(值2),(值 ...
- 多进程和mongo的配合使用
这篇文章主要是讲在多线程下使用mongo数据库的一个报错,算是一个警告,如下: /usr/lib64/python2.6/site-packages/pymongo/topology.py:75: U ...
- MFC里面解析json文件格式
CString strTemp; //CString ->string; string stringMsg = (LPCSTR)(CStringA)strTemp; //string -> ...
- java 小心使用float和double他可能不如你所想
public static void main(String[] args) { double funds=1.00; ; // ; ;funds>=price;price+=.){ funds ...
- Python 多进程编程之 进程间的通信(Queue)
Python 多进程编程之 进程间的通信(Queue) 1,进程间通信Process有时是需要通信的,操作系统提供了很多机制来实现进程之间的通信,而Queue就是其中的一个方法----这是操作系统开辟 ...
- ABP框架系列之五十二:(Validating-Data-Transfer-Objects-验证数据传输对象)
Introduction to validation Inputs of an application should be validated first. This input can be sen ...
- Hibernate配置文件的书写
Hibernate主要配置文件 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibern ...