Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1674284
  • 博文数量: 782
  • 博客积分: 2455
  • 博客等级: 大尉
  • 技术积分: 4140
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-06 21:37
个人简介

Linux ,c/c++, web,前端,php,js

文章分类

全部博文(782)

文章存档

2015年(8)

2014年(28)

2013年(110)

2012年(307)

2011年(329)

分类: 嵌入式

2013-03-12 09:23:49

/*
 * 文件名:debug.h
 * 摘要:用于打印调试信息
 * 		为了统一控制打印信息是否输出,而用宏定义的打印函数。同时也可以起到开发版本与发布版本是同一个版本
 *  Created on: 2013-1-10
 *      Author: lzy
 */

#ifndef DEBUG_H_
#define DEBUG_H_

#include 
#include 
#include 
#include 

#define 	DEBUG_SWITCH	1		/* 打开调试信息打印功能 */
#define     ERR_DEBUG_SWITCH	1	/* 打印错误信息打印功能 */
#define   EXAM_ASSERT_TEST_        1	/* 开启断言 */

/**
 * 简单打印调试信息
 */
#if    DEBUG_SWITCH
#define PR_DEBUG(fmt,args...) fprintf(stderr,fmt, ##args)
#else
#define PR_DEBUG(fmt,args...) /*do nothing */
#endif

/**
 * 错误信息打印
 * 自动打印发生错误时代码所在的位置
 */
#if    ERR_DEBUG_SWITCH
#define PR_ERR(fmt,args...) fprintf(stderr,"\nError:\nFile:<%s> Fun:[%s] Line:%d\n "fmt, __FILE__, __FUNCTION__, __LINE__, ##args)
#else
#define PR_ERR(fmt,args...) /*do nothing */
#endif

/**
 * 断言
 * 对某种假设条件进行检查(若条件成立则无动作,否则报告错误信息)
 */
#ifdef EXAM_ASSERT_TEST_ // 若使用断言测试
#define EXAM_ASSERT(condition, fmt, args...)  \
({ if(condition)	\
	{	\
		fprintf(stderr,"\nError:\nFile:<%s> Fun:[%s] Line:%d\n "fmt, __FILE__, __FUNCTION__, __LINE__, ##args);	\
	        abort();	\
	}	\
})

#else // 若不使用断言测试
#define EXAM_ASSERT(condition, fmt, args...) NULL
#endif

#endif /* DEBUG_H_ */
阅读(945) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~