Chinaunix首页 | 论坛 | 博客
  • 博客访问: 455415
  • 博文数量: 724
  • 博客积分: 40000
  • 博客等级: 大将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 14:47
文章分类

全部博文(724)

文章存档

2011年(1)

2008年(723)

我的朋友

分类:

2008-10-13 16:58:22

1,(C99)
#ifdef DEBUG
#include
#define debug(...) \
 do\
 { \
  printf("%s#%s(Line %d) ",__FILE__,__FUNCTION__,__LINE__);\
  printf(__VA_ARGS__);\
 }while(0)
#else
#define debug(x...)
#endif

2,(C99)
#ifdef DEBUG
#include
#define debug(x...) \
        do\
        {\
                printf("%s#%s(Line %d) ",__FILE__,__FUNCTION__,__LINE__);\
                printf(x);\
        }while(0)
#else
#define debug(x...)
#endif


3,
#include
#include
void user_printf(const char * format,...)
{
    va_list arg;
   
    printf("%s#%s(Line %d) ",__FILE__,__FUNCTION__,__LINE__);
    va_start(arg,format);
    vprintf(format,arg);
    va_end(arg); 
}

#ifdef DEBUG
#define debug user_printf
#else
#define debug
#endif
注:3有问题,FILE, FUNCTION和LINE返回的是当前函数的结果,C规范中有没有规定获取函数被调用位置的类似结果呢?如果你知道,麻烦告知,谢谢!


--------------------next---------------------

阅读(208) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~