[宏]__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 ...
随机推荐
- js----作用域链
作用域链是javascript的一个难点,要了解它就要了解作用域.变量.执行环境.生命周期等. 下面是找的资料加总结,加深理解. 作用域 变量的作用域可分为 A:全局作用域----最外层函数定义的变量 ...
- cdnbest自定义错误显示节点名教程
在自定义错误里选择js选项,输入: document.write("error!" + hostname); 这是最简单的写法,只显示节点名,如果要显示其他效果,可自已修改js
- JS 操作样式 style
1. 任何支持 style 特性的 HTML 元素在 JavaScript 中都对应着有一个 style 属性,指向一个 CSSStyleDeclaration 的一个实例对象,包含该元素的内嵌sty ...
- hive的常用操作
1.hive的数据类型 tinyint/smallint/int/bigint tinyint:从 0 到 255 的整型数据 smallint:从 0 到 65535 的整型数据 int:从 0 到 ...
- netty(二) 创建一个netty服务端和客户端
服务端 NettyServer package com.zw.netty.config; import com.zw.netty.channel.ServerInitializer;import io ...
- ToolBar+Drawable实现一个好用的侧滑栏(侧边栏)和工具栏
先参考下ToolBar的使用和DrawableLayout的使用: 1.主界面布局,主要结构包含一个ToolBar和一个DrawableLayout,DrawableLayout里面有左侧边栏布局和主 ...
- FortiGate日志中session clash
1.出现于:FortiGate v5.0和v5.2 2.出现原因 Session clash messages appear in the logs when a new session is cre ...
- c#: Label控件加入AutoHeight属性
此功能在界面布局中颇为实用,录代码以记之: public class LabelEx : Label { private bool autoHeight = true; [DefaultValue(t ...
- [leetcode]15. 3Sum三数之和
Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find ...
- DVR NVR
1.NVR: 是(Network Video Recorder即网络硬盘录像机)的缩写.NVR最主要的功能是通过网络接收IPC(网络摄像机)设备传输的数字视频码流,并进行存储.管理,从而实现网络化带来 ...