/*****************************strcat*****************************************//* # 字符串化 */#defineexp(s) #s // exp(145s) <==> "145s" /* ##为连接符,用来将宏参数或其他的串连接起来 */#defineSTR_TO_CAT(a, b) a##b // strcat(a, b) <==> STR_TO_CAT(a, b) #defineCON1(a, b) a##e##b // CON1(2.5, 2) <==> 2.5e2 == 250 #defineCON2(a, b) a##b##00// CON2(2.5, 2) <==> 2.5200
日志的打印等级
/*****************************strcat*****************************************/#ifndef_DEBUG_H#define_DEBUG_H/*
* when PRINTF_LEVEL == 1
* printf("This is a debug information maro!!!"); <==> LOG("This is a debug information maro!!!");
* printf("a = %d, b = %f\n", a, b); <==> LOG("a = %d, b = %f\n", a, b);
*
*/#include<stdio.h>/*****************************SelfPrintf***********************************************/#definePRINTF_LEVEL0#if(PRINTF_LEVEL ==0)#defineLOG(...)printf("COMMON_DEBUG ======= :"__VA_ARGS__)#defineLOG_ERROR(err_msg)\do{\printf("COMMON_DEBUG_ERROR=======: %s:%s:%d",__FILE__, __FUNCTION__,__LINE__);\printf(" (err_msg:%s)\n", err_msg);}while(0); \
#elif(PRINTF_LEVEL ==1)#defineLOG(...)printf(__VA_ARGS__)#defineLOG_ERROR(err_msg)\do{\printf("ERROR=======: %s:%s:%d",__FILE__, __FUNCTION__,__LINE__);\printf(" (err_msg:%s)\n", err_msg);\}while(0);#else#defineLOG(...)#defineLOG_ERROR(err_msg)#endif#endif
调试必备宏定义
#defineDBG_ERR_IFO(fmt, args...)printf("The position of error information[%s:%s(%d)]:"fmt "\n",__FILE__,__FUNCTION__,__LINE__,##args)// 第一个参数传给fmt, // 第二个参数开始传给args..., // #fmt的=的意思是把fmt传进来的内容以字符串形式输出// ##args的意思=是把args...中的多个参数串连起来。DBG_ERR_IFO(“the value a =%d, b =%d\n”, a, b);
⇒ printf("The position of error information[%s:%s(%d)]:" “the value a =%d, b =%d\n” "\n",__FILE__,__FUNCTION__,__LINE__, a, b);