C/C++宏定义中#与##区别
2015-06-24 17:30
387 查看
// #表示:对应变量字符串化 // ##表示:把宏参数名与宏定义代码序列中的标识符连接在一起,形成一个新的标识符 #include <stdio.h> #define trace(x, format) printf(#x " = %" #format "\n", x) #define trace2(i) trace(x##i, d) int main() { int i=1; char *s="three"; float x=2.0; trace(i, d); // 相当于 printf("x = %d\n", x) trace(x, f); // 相当于 printf("x = %d\n", x) trace(s, s); // 相当于 printf("x = %d\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; }
相关文章推荐
- smartFoxServer 2x C++环境的搭建
- VC++读取图像RGB值
- VC++读取图像RGB值
- C++类、结构、对象内存浅析(sizeof)(很重要)
- vs2012警告未能加载包“visual c++ package”
- 使用C语言计算utf-8字符串长度
- 【Effective C++ 读书笔记】导读 Introduction
- C++13.1复制控制
- 层次状态机的实现 c语言
- const 在c c++语言中的不同
- 《Effective C++》学习笔记——条款33
- C++ 获取当前项目Debug中文件的路径(GetModuleFileName())
- C/C++中extern关键字详解
- 装饰模式
- C语言宏嵌套问题
- C++用new和不用new创建类对象的区别
- C++虚函数之虚表
- [VC++]UpdateData(true)的重要性
- Effective C++ 条款17
- 如何使用C/C++为Python编写DLL/SO