本文共 1056 字,大约阅读时间需要 3 分钟。
#cat pre.c
#include#gcc -E pre.c | tail -20/* * 宏定义中, *# 宏函数参数字符串化 *## 用来连接两个标识符 * (通常其中一个标识符是宏函数的参数)为一个标识符 **/#define PRINT(x) printf(#x" = %d\n", x)#define GENERATOR(type) \ type max_##type(type a, type b)\ {\ return a > b ? a : b; \ }GENERATOR(int)GENERATOR(double)GENERATOR(char)int main(){ int x = 100; printf("x = %d\n", x); int y = 200; printf("y = %d\n", y); printf("---------------\n"); PRINT(x); PRINT(y);// ==> printf("y""=%d\n", y); printf("max_int(10, 20) = %d\n", max_int(10, 20)); printf("max_double(10.3, 20.4) = %g\n", max_double(10.3, 20.4));}
# 2 "pre.c" 2# 15 "pre.c"int max_int(int a, int b) { return a > b ? a : b; }double max_double(double a, double b) { return a > b ? a : b; }char max_char(char a, char b) { return a > b ? a : b; }int main(){ int x = 100; printf("x = %d\n", x); int y = 200; printf("y = %d\n", y); printf("---------------\n"); printf("x"" = %d\n", x); printf("y"" = %d\n", y); printf("max_int(10, 20) = %d\n", max_int(10, 20)); printf("max_double(10.3, 20.4) = %g\n", max_double(10.3, 20.4));}
转载地址:http://uxuhj.baihongyu.com/