原文来自:dadaguo3000的专栏
#include <stdio.h> #define MIN(x, y) (x < y ? x : y) #define TO_STRING(x) TO_STRING1(x) #define TO_STRING1(x) #x int main() { const char *str = TO_STRING(MIN(1, 2)); printf(str); return 0; }
#和##. 前者用来将一个文本转化为语言内字符串, 后者用来连接两个文本
例:
#define TO_STRING(s) #s
#define CAT(a, b) a#b
TO_STRING(a) => "a"
int CAT(a, b); => int ab;