#include <stdio.h>
//#的作用:下面代码相当于声明一个字符串STR[],s就是STR[]中的字符
#define STR(s) # s
//##作用:将a, b 合成一个新的变量c(假设为c, c = ab). Note:c必须有声明或为常数,如 STR1(1, 2) = 12
#define STR1(a, b) a ## b
//...作用:...表示可变参数,而后面__VA_ARGS__相当与函数中printf()中的%d.
//Note:在__VA_ARGS_前加#,则传入实参时不用"",否则加上""
#define showlist(...) printf(#__VA_ARGS__)
#define report(test, ...) ((test)?printf(#test):printf(__VA_ARGS__))
int main(void)
{
int alanwelcome = 3;
int x = 3;
int y = 4;
printf(STR(hello world\n));
printf("%d\n",STR1(alan, welcome));
showlist(The first, second, third items);
report(x > y, "the bigger number is %d", y);
return 0;
}
初学预处理,做个笔记。。。
本文详细介绍了C语言预处理宏的使用方法,包括基本的字符串宏定义、连接宏定义及可变参数宏定义等,并通过具体示例展示了这些宏如何在实际编程中应用。
665

被折叠的 条评论
为什么被折叠?



