c/c++中#号的用法
来源:互联网 发布:aster数据下载 编辑:程序博客网 时间:2024/06/07 02:25
转载:http://blog.sina.com.cn/s/blog_4cf015f201009o1d.html
第一种情况作为Stringizing Operator(#),暂叫字符串化吧。
#define stringer( x ) printf( #x "\n" )
int main()
{
stringer( In quotes in the printf function call\n );
stringer( "In quotes when printed to the screen"\n );
stringer( "This: \" prints an escaped double quote" );
}
如此的定义在进行处理时将被转换为如下代码:
int main()
{
printf( "In quotes in the printf function call\n" "\n" );
printf( "\"In quotes when printed to the screen\"\n" "\n" );
printf( "\"This: \\\" prints an escaped double quote\"" "\n" );
}
程序运行结果如下:
In quotes in the printf function call
"In quotes when printed to the screen"
"This: \" prints an escaped double quotation mark"
例子:
#define makechar(x) #@x
causes the statement
a = makechar(b);
这条语句将被扩展为
a = 'b';
注意单引号字符不能使用这样的字符化。
第三种情况作为
Token-Pasting Opertor(##),叫做连接符吧,大概是这样的意思。
例子:#define paster( n ) printf( "token" #n " = %d", token##n ) int token9 = 9;
如果一个数字作为此宏的参数调用的话,paster( 9 );
宏被展开为
printf( "token" "9" " = %d", token9 );
进而成为这样的语句:printf( "token9 = %d", token9 );
参考链接:http://blog.sina.com.cn/s/blog_4cf015f201009o1d.html
- c中 ## 的用法
- c/c++中#号的用法
- c/c++中#号的用法
- [c、c++]宏中"#"和"##"的用法
- [c、c++]宏中"#"和"##"的用法
- C 中 sizeof的用法
- C中“##”符号的用法
- c中static的用法
- c 中 static的用法
- C中static的用法
- c中static的用法
- C中volatile的用法
- c中atexit的用法
- C中union的用法
- C中violatile的用法
- C语言中##的用法
- C语言中 ^的用法
- C中#line的用法
- 详解 Android 的 Activity 组件
- Ubuntu14.04 make menuconfig 的错误
- Android Xutils 框架
- Android Wifi控制方法总结
- ArcGIS教程:检查多个数据集的协变
- c/c++中#号的用法
- MATLAB多维数组操作
- 美图3
- Mongodb VS Hbase
- 初次使用nmap
- 黑马入学_学习blog_第七篇
- IT忍者神龟之date日期回顾
- 如何理解TCP长连接
- Onvif开发之代码框架生成篇