cpp 中的 #, ##, #@
来源:互联网 发布:建立党建工作网络平台 编辑:程序博客网 时间:2024/05/21 10:32
#表示:对应变量字符串化 ##表示:把宏参数名与宏定义代码序列中的标识符连接在一起,形成一个新的标识符连接符#@:它将单字符标记符变换为单字符,即加单引号。例如:#define B(x) #@x 则B(a)即'a',B(1)即'1',但B(abc)却不甚有效。
#include <stdio.h> #define trace(x, format) printf(#x " = %" #format "\n", x) #define trace2(i) trace(x##i, d) int _tmain(int argc, _TCHAR* argv[]) { int i = 1; char *s = "three"; float x = 2.0; trace(i, d); // 相当于 printf("x = %d\n", x) trace(x, f); // 相当于 printf("x = %f\n", x) trace(s, s); // 相当于 printf("x = %s\n", x) int x1 = 1, x2 = 2, x3 = 3; trace2(1); // 相当于 trace(x1, d) trace2(2); // 相当于 trace(x2, d) trace2(3); // 相当于 trace(x3, d) return 0; }
输出结果:
i = 1
x = 2.000000
s = three
x1 = 1
x2 = 2
x3 = 3
引用自:
http://blog.csdn.net/hellokandy/article/details/50592971
阅读全文
0 0
- cpp 中的 #, ##, #@
- CPP 中的一些基本概念
- cpp中的volatile关键字
- cpp中的类型转换
- cpp中的STL简介
- [cpp]C++中的托管
- CPP中的this指针
- Cpp.Study.Note.初识 Cpp中的类
- cpp中的句柄 (二)
- cpp中的输出运算符
- [cpp]C++中的宏定义
- base_conv_layer.cpp中的参数理解
- 如何在一个cpp中调用另一个cpp中的类?
- 如何在一个cpp中调用另一个cpp中的类?
- cpp
- CPP
- CPP
- cpp
- Android 圆形头像+渐变+白框
- 怎么在oracle数据库创建用户,并赋权限
- ResponseUtil
- 希尔排序和快速排序
- tlb、tlh和tli文件的关系
- cpp 中的 #, ##, #@
- Codeforces785D. Anton and School
- 第二篇:JAVA网络编程之UDP Socket(含代码)
- 网络流 最小割
- Could not find or load main class(找不到或无法加载主类)
- 51Nod1463 找朋友(离线处理+树状数组维护区间最大值)
- poj 3625 Building Roads (prim)
- secureCRT如何通过SSH2连上ubuntu
- Atlassian系列软件破解研究记录