宏定义的字符串连接##和字符串化#
2014-03-18 18:54
204 查看
宏定义无## 和 #, 参数继续展开;否则就不继续展开
例:
1、#define A(line) shit_##line
#define B(line) A(line)
#define C int B(__LINE__)
C; --> int shit_行号;
////////////////////////////////////////
2、
// 宏定义涉及到字符串连接##,字符串化#, 则参数__LINE__不继续展开
#define B(line) shit_##line
#define C int B(__LINE__)
C; --> int shit___LINE__;
////////////////////////////////////////
3、
#define A holy
#define B shit
#define C(a, b) a##_##b
#define D(a, b) C(a, b)
#define E D(A, B)
E; -->holy_shit
////////////////////////////////////////
4、
#include <stdio.h>
#define M 1
#define N 2
#define A(a,b) a##b, a+b
#define B(a) #a, a
#define C(a) B(a)
int main()
{
char *MN = "here";
printf("%s, %d, %d\n", C(A(1,2))); --> 12, 1+2, 12, 3
printf("%s, %d, %d\n", B(A(1,2))); --> A(1,2), 12, 3
printf("%s, %d\n", A(M,N)); --> here, 3
return 0;
}
C(a)的宏定义无## 和 #, A(1,2)会被展开成12, 1+2;B(a)宏定义有#,带#的a A(1,2)不会继续展开,不带#的展开成12, 1+2;
相关文章推荐
- 宏定义中字符串连接操作
- C++ 宏定义中字符串连接操作
- [转]宏定义中字符串连接操作
- 宏定义中字符串连接操作
- C语言中如何使用宏连接多个字符串(#和##的用法)
- 宏定义中字符串连接操作
- C++ ## 宏定义中字符串连接操作
- 宏定义字符串连接和符号粘贴
- C++ 宏定义中字符串连接操作
- java中不同数据库连接字符串
- C#连接Oracle数据库的字符串
- web.config connectionStrings 数据库连接字符串的解释(转载)
- 数据库连接字符串大全
- 连接字符串中的integrated security=true的意思是什么
- 字符串分解和连接
- 【C语言训练】字符串正反连接
- 连接一个字段为字符串
- 宏定义中的#和##
- c# 连接字符串数据库服务器端口号 .net状态服务器端口号
- Winform添加App.config文件,和调用连接字符串的两种写法