Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7549924
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: 嵌入式

2013-01-15 10:07:22

/*
 * 文件名: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_ */
阅读(4530) | 评论(0) | 转发(2) |
0

上一篇:串口通信程序

下一篇:单目录通用Makefile

给主人留下些什么吧!~~