设为首页 加入收藏

TOP

C语言中##的用法
2014-11-23 22:57:45 来源: 作者: 【 】 浏览:1
Tags:言中 用法
C语言中##称为连接符,其功能是在带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串。
要注意下面的用法:
1、
[cpp]
#include
#define debug(format, args...) fprintf(stderr, format, args)
void main(void){
debug("Test \n");
return;
}
有的说这种情况下字符串后面会多一个逗号,但是我用gcc编译不通过;
2、
[cpp]
#include
#define debug(format, args...) fprintf(stderr, format, ##args)
//#define debug(format, args...) fprintf(stderr, format, args)
void main(void){
debug("Test \n");
return;
}
这样可以编译通过,执行正确;
3、
[cpp]
#include
//#define debug(format, args...) fprintf(stderr, format, ##args)
#define debug(format, args...) fprintf(stderr, format, args)
void main(void){
debug("Test%d \n",1);
return;
}
这样也正确;
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C 专家编程 笔记(一、二章) 下一篇c语言结构体和联合体例题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: