macro特殊用法

#的使用方法(因为老是忘,所以记录于此):

Quoting macro arguments(当字符串引用)

#define QUOTEME(x) #x

the code

printf("%s\n", QUOTEME(1+2));

will expand to

printf("%s\n", "1+2");

Token concatenation(Token当做字符串连接)

#define MYCASE(item,id) \
case id: \
item##_##id = id;\
break

switch(x) {
MYCASE(widget,23);
}

The line MYCASE(widget,23); gets expanded here into

case 23:
widget_23 = 23;
break;


Standard predefined positioning macros

// debugging macros so we can pin down message origin at a glance
#define WHERESTR "[file %s, line %d]: "
#define WHEREARG __FILE__, __LINE__
#define DEBUGPRINT2(...) fprintf(stderr, __VA_ARGS__)
#define DEBUGPRINT(_fmt, ...) DEBUGPRINT2(WHERESTR _fmt, WHEREARG, __VA_ARGS__)
//...

DEBUGPRINT("hey, x=%d\n", x);

或者:
#define DEBUGPRINT2(args...) fprintf(stderr, ## args) //注意args与##之间有空格,特殊用法




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值