预处理器支持文本宏替换和类函数文本宏替换。不带参数的宏形式#define identifier replacement-list 这是不带参数的宏也叫 “对象式宏”作用是做简单的文本替换。例如#includestdio.h#defineINSTRUCTION_CACHE_ENABLE1U#defineMY_MESSAGEhellointmain(){printf(%u\n,INSTRUCTION_CACHE_ENABLE);printf(%s\n,MY_MESSAGE);return0;}运行输出带参数的 “类函数宏”固定参数形式#define identifier ( parameters ) replacement-list例如#includestdio.h#defineMAX(x,y)((x)(y)?(x):(y))intmain(){printf(%d\n,MAX(1,2));printf(%d\n,MAX(200,2));return0;}运行输出固定参数可变参数形式#define identifier ( parameters, ... ) replacement-list可变参数会被__VA_ARGS__接收过来。例如#includestdio.h#definePRT(format,...)printf(format,__VA_ARGS__)intmain(){PRT(hello %d\n,1);PRT(hello %d %s\n,1,good);return0;}运行输出纯可变参数形式#define identifier ( ... ) replacement-list(…)参数列表只有一个 …表示纯可变参数可以接收任意数量的参数包括 0 个。可变参数会被__VA_ARGS__接收过来。例如#includestdio.h#definePRT(...)printf(__VA_ARGS__)intmain(){PRT(hello\n);PRT(hello %d %s\n,1,good);return0;}运行输出