分类: C/C++
2009-11-12 11:49:02
这种方法对debug调试很有作用。
#define cprintf(fmt, args...) do { \
FILE *fp = fopen("/dev/console", "w"); \
if (fp) { \
fprintf(fp, fmt, ## args); \
fclose(fp); \
} \
} while (0)
#define dprintf(fmt, args...) cprintf("==> DEBUG %s: " fmt, __FUNCTION__, ## args)
c语言下面这种实现方法:
#include
#include
#include
int demo(char, ...);
int main(void){
demo ("demo","This","is","a","demo!","\0");
return 0;}
int demo( char msg,...)
{
va_list argp;
int argno = 0;
char *para;
va_start(argp,msg);
while (1) {
para = va_arg( argp, int );
if (strcmp(para, "\0") == 0)
break;
printf("Parameter #%d is:%s\n", argno, para);
argno++;
}
va_end(argp);
return 0;}