C语言添加DEBUG,可以显示时间、文件、函数、行对于调试时比较方便

#include 
#include 
#include 
#include 
 
#define GlobalDebugFlag 1
 
#define DEBUG_PRINT_WITH_TIME(fmt, args...) { \
                    do \
                    { \
                        if (GlobalDebugFlag == 1 ) \
                        { \
                            time_t timep = {0}; \
                            struct tm *p = NULL; \
                            time(&timep); \
                            p=localtime(&timep); \
                            fprintf(stdout, "[%4d-%02d-%02d %02d:%02d:%02d %s %s %d] ", \
                            (1900+p->tm_year), \
                            (1+p->tm_mon), \
                            p->tm_mday,  \
                            p->tm_hour, \
                            p->tm_min,  \
                            p->tm_sec, \
                            __FILE__, \
                            __FUNCTION__, \
                            __LINE__); \
                           fprintf(stdout, fmt "\n", ##args); \
                        } \
                    } \
                    while(0); \
					}

你可能感兴趣的:(c++)