一篇比较好的文章

可变参数宏不被ANSI/ISO C++ 所正式支持。因此,你应当检查你的编译器,看它是否支持这项技术。

GCC 提供的可变参数

#ifdef DEBUG 
#define dbgprint(format,args...) \ 
fprintf (stderr, format, ##args) 
#else
#define dbgprint(format,args...) 
#endif

支持 c99

gcc -c -std=c99

例子(已测试)

#include <stdio.h>
#include <stdarg.h>

static int debug_on = 1;

#define debugmsg(...) \
do{ \
    if( debug_on == 0 ) break;\
    fprintf(stderr, "%s:%d ", __func__, __LINE__);\
    fprintf(stderr, __VA_ARGS__);\
}while(0);

int main()
{

    debugmsg("%s\n", "helloword");
    return 0;
}