现在的位置: 首页 > 综合 > 正文

查看宏展开之后的代码

2013年08月01日 ⁄ 综合 ⁄ 共 337字 ⁄ 字号 评论关闭

原文来自: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;

抱歉!评论已关闭.