C语言中##称为连接符,其功能是在带参数的宏定义中将两个子串(token)联接起来,从而形成一个新的子串。
要注意下面的用法:
1、
#include <stdio.h> #define debug(format, args...) fprintf(stderr, format, args) void main(void){ debug("Test \n"); return; }
有的说这种情况下字符串后面会多一个逗号,但是我用gcc编译不通过;
2、
#include <stdio.h> #define debug(format, args...) fprintf(stderr, format, ##args) //#define debug(format, args...) fprintf(stderr, format, args) void main(void){ debug("Test \n"); return; }
3、
#include <stdio.h> //#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; }