c常用几个调试使用的宏定义 c常用几个调试使用的宏定义 c常用几个调试使用的宏定义 c常用几个调试使用的宏定义 makefile 打印 c语言全局变量不能定义在.h中,需要定义在.c中,再 extern 到.h中并且.h不能赋值
T507 UBOOT 打印
tick_printf("func:%s \t line:%d\n", __func__,__LINE__);
tick_printf("func:%s \t line:%d \tval:%d\n", __func__,__LINE__,val);
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#define mydebugAddr(msg) printf("%s: %s:line %d %s:%p\n", __FILE__, __func__, __LINE__,#msg,msg);
#define mydebugGetUs {struct timeval tv_start; gettimeofday(&tv_start, NULL); uint64_t start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec);start_ms;}
/* return a+b 带返回值的宏定义 */
#define A_PLUS_B_MACRO(a, b) ({int ret; ret = (a) + (b); ret;})
#define A_PLUS_B_MACRO2(a, b) ({int ret; ret = add((a), (b)); ret;})
内核打印
printk(" %s \t %d\n",__func__,__LINE__);
printk(" %s \t %d \t val:%d\n",__func__,__LINE__,period_ns);
#define mydebug printf("[%s %s] %s: %s: %d\n", __DATE__, __TIME__, __FILE__, __func__, __LINE__);
#define mydebugMsg(msg) printf("[%s %s] %s: %s: %d msg:%s\n", __DATE__, __TIME__, __FILE__, __func__, __LINE__,msg);
#define mydebugNum(msg) printf("[%s %s] %s: %s: %d num:%d\n", __DATE__, __TIME__, __FILE__, __func__, __LINE__,msg);
#define mydebugHex(buf,len) do {\
unsigned char* __buf_ptr = (unsigned char*) (buf); \
printf("[%s %s] %s: %s: %d %s: ", __DATE__, __TIME__, __FILE__, __func__, __LINE__, #buf); \
for( int i = 0; i < (len); i ++){ \
printf("%02X ", __buf_ptr[i]); \
} \
printf("\n"); \
} while(0);
//static uint64_t start_ms_mydebugCalusStart__inner_used=0;
#define getustimestampCalusCurrent() ({ struct timeval tv_start; gettimeofday(&tv_start, NULL); (tv_start.tv_sec * 1000000 + tv_start.tv_usec); })
#define mydebugCalusStart static uint64_t start_ms_mydebugCalusStart__inner_used = getustimestampCalusCurrent();
#define mydebugCalusUpdate(msg) {start_ms_mydebugCalusStart__inner_used = getustimestampCalusCurrent()-start_ms_mydebugCalusStart__inner_used; printf("%s: %s: %d \t us:[%ld] %s:%s\n", __FILE__, __func__, __LINE__,start_ms_mydebugCalusStart__inner_used,#msg,msg);}
#define mydebugCalusEnd(msg) {uint64_t start_ms_mydebugCalusEnd = getustimestampCalusCurrent()-start_ms_mydebugCalusStart__inner_used; printf("%s: %s: %d \t us:[%ld] %s:%s\n", __FILE__, __func__, __LINE__,start_ms_mydebugCalusEnd,#msg,msg);}
#define mydebugUs do{struct timeval tv_start; gettimeofday(&tv_start, NULL); uint64_t start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec);printf("[%ld] %s: %s: %d\n", start_ms, __FILE__, __func__, __LINE__);} while(0);
//mydebugUs 显示一次大概需要50微秒(1Ghz的板子测试结果)
#define HexStrToArray(data,_datalen,outbuf) { unsigned char _tem; char __t; for(int i=0;i<_datalen;i+=2){ \
__t = *(data+i); if(__t>=0x30 && __t<=0x39){_tem=(__t-0x30)<<4;} else if(__t>=0x41 && __t<=0x46){_tem=(__t-55)<<4;} else if(__t>=0x61 && __t<=0x66){_tem=(__t-87)<<4;} else {break;} \
__t = *(data+i+1); if(__t>=0x30 && __t<=0x39){_tem+=__t-0x30;} else if(__t>=0x41 && __t<=0x46){_tem+=__t-55;} else if(__t>=0x61 && __t<=0x66){_tem+=__t-87;} else {break;} \
*(outbuf+i/2)=_tem; } }
#define ArrayToHexStr(data,_datalen,outbuf) { char hex_lookup[16] = { '0', '1', '2', '3', '4', '5', '6', '7','8','9', 'A', 'B', 'C', 'D', 'E', 'F' }; for(int i=0;i<_datalen;i++){ outbuf[2*i]=hex_lookup[data[i]>>4]; outbuf[2*i+1]=hex_lookup[data[i]&0x0F]; } }
c的debug打印
#define mydebugfmt(fmt, args...) printf("__line:%d \t__func:%s \t__file:%s \t", __LINE__, __func__, __FILE__);printf(fmt, ##args);
makefile打印
$(info __debuginfo__ $(CSRCS))
c语言全局变量不能定义在.h中,需要定义在.c中,再 extern 到.h中并且.h不能赋值


c语言 strchr 查找不到会返回 \0 也就是空NULL strlen(NULL)程序会崩溃所以计算
int strlennull(char* str){
if(str){
return strlen(str);
}
else{
return 0;
}
}
//
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2020-08-09 c语言一点小觉悟(1)