linux C下 利用宏函数打印调试信息
来源:互联网 发布:网店美工学生实训报告 编辑:程序博客网 时间:2024/06/05 11:03
/*****************************************************
这个代码里面
把字符串根据指定的分割符可以拆分,合并
主要是运用了一个宏来打印调试信息
函数调试好以后可以注释掉此行使,程序打印调试信息的代码不编译进去
__LINE__:在源代码中插入当前源代码行号;
__FILE__:在源文件中插入当前源文件名;
__DATE__:在源文件中插入当前的编译日期
__TIME__:在源文件中插入当前编译时间;
__STDC__:当要求程序严格遵循ANSI C标准时该标识被赋值为1;
__cplusplus:当编写C++程序时该标识符被定义。
******************************************************/
#include <netinet/in.h>
#include <pthread.h>#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#define __DEBUG__
//#undef __DEBUG__ //函数调试好以后可以注释掉此行使,程序打印调试信息的代码不编译进去
#ifdef __DEBUG__
#define DEBUG(format,...) \
printf("File: "__FILE__", Line: %05d, FUNCTION: %s ::"format"\n", __LINE__,__FUNCTION__, ##__VA_ARGS__)
#else
#define DEBUG(format,...)
#endif
char *p = NULL;
char *q = NULL;
int i = 0;
p = q = fatherstr;
while(p = strchr(p,key))
{
strncpy(child[i],q,p-q);
child[i][p-q] = '\0';
p = p+1;
q = p;
i ++;
}
}
void cat_childstr(unsigned char child[][30],int child_num,char *fatherstr,char key){
int i,len ;
for(i=0;i<child_num;i++)
{
strcat(fatherstr,child[i]);
len = strlen(fatherstr);
fatherstr[len]=key;
fatherstr[len+1]= '\0';
}
fatherstr[len]='\0';
}
int main( void )
{
unsigned char color_child[4][30];
unsigned char color[5]={ 145,233,222,238,0 };
char fatherstr[17]={0};
int chil_num = 4;
int i;
for(i=0;i<4;i++)
{
char str[4];
sprintf(str, "%u", color[i]);
strcpy(color_child[i],str);
DEBUG("main %u**%s**%s\n",color[i],str,color_child[i]);
}
cat_childstr(color_child,4,fatherstr,',');
DEBUG("%s",fatherstr);
DEBUG("%s\n\n",fatherstr);
}
//结果:
我这个项目唯一的串口用来控制单片机了,所以如果要用串口来调试,必须在编译的时候屏蔽掉所有串口读写函数,可以用以下几步做到
1、将所有与串口读写有关的函数写到一个文件里
2、所有的函数里面有预编译命令处理
int function( )
{
#ifdef __SERIOL__
函数体
return 0;
#else
return -1;
#endif
}
3、在次文件头上加上
#define __SERIOL__
//#undef __SERIOL__
如果其他调试完成以后把//注释去掉即可。
4、本文件的函数在其他文件的函数中正常调用即可,只是有宏的时候是个空函数,直接return -1编译器不会报错。
阅读全文
0 0
- linux C下 利用宏函数打印调试信息
- 关于linux下c编程利用条件编译打印信息调试
- C 打印调试信息的宏函数
- linux C宏定义实现打印调试信息
- Linux下的C编程(打印函数)
- Linux下利用printf函数打印带颜色的字符串
- 一个方便打印C程序调试信息的宏
- MFC 如何调用打印调试信息函数
- 集中打印调试信息的模版函数
- c语言编码 调试信息打印方法
- Linux下打印调试管理
- Linux下利用ioctl函数获取网卡信息
- Linux下利用ioctl函数获取网卡信息
- 在linux启动过程打印调试信息
- Linux驱动调试手段:打印信息日志
- linux中使用backtrace打印调试信息
- C语言下调试信息打印与错误位置定位功能的实现
- c语言可变参宏函数实现打印Debug信息
- 双十一的正确姿势 · qml和QT的交互初学
- python语法
- remote: Permission to xxxxx/javaeelzw.git denied to xxxx. fatal: unable to access 'https://git
- Ubuntu下sourceInsight安装
- void *变量用法
- linux C下 利用宏函数打印调试信息
- 欢迎使用CSDN-markdown编辑器
- A 2017 Guide to Semantic Segmentation with Deep Learning
- win10如何设置休眠选项
- 在Centos7 上安装SVN
- C# :自己动手实现:使用数组的方式实现List
- c语言练手——记录1
- python---xpath使用
- webots自学笔记(二)节点与机器人建模