[CPP]宏的字符串处理
来源:互联网 发布:mac散热不好烫手 编辑:程序博客网 时间:2024/05/22 11:46
宏定义无## 和 #, 参数继续展开;否则就不继续展开
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;
0 0
- [CPP]宏的字符串处理
- Cpp--处理字符串的自定义类
- cpp:处理字符串与数字的混合输入(动态数组)
- cpp的处理流
- 【字符串处理】文明的复兴 words.pas/c/cpp/in/out
- 字符串每个单词的反转.cpp
- cpp: 读取字符串的最简便方式
- Cpp的异常处理Exception Handling-笔记
- 一个简单的CPP处理框架
- f0305.cpp 字符串操作
- strDivide2.cpp字符串划分
- cpp 字符串加密 解密
- 【Cpp】删除字符串空格
- c cpp字符串比较
- moc处理cpp文件
- moc处理cpp文件
- 异常处理.cpp
- 读取cpp文件处理
- 图片三级缓存
- defer和async的详细区别
- MVP模式+Dagger2+Rxjava+retrofit2+lambda表达式 … retrofit2带进度的上传下载
- CentOS 搭建hadoop2.7.2
- CSS深入理解vertical-align和line-height的基友关系
- [CPP]宏的字符串处理
- JavaWEB采用Filter的权限管理
- 博客的第一天
- php中heredoc的使用方法
- c++模板的定义和实现为啥分开
- SpringMVC框架搭建及详解
- UML—概述
- Appium 自动化用例设计(Excel 配置篇)
- 数组是对象吗?