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;
    }
}

 

 

 


 

 

 
//
posted @   小城熊儿  阅读(95)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2020-08-09 c语言一点小觉悟(1)
点击右上角即可分享
微信分享提示