• Debug Logs


    logs.h

    #ifndef _LOGS_H_
    #define _LOHS_H_
    #include <stdio.h>
    
    #define DEBUG    1
    #define _LTS_AM    1
    #define _LTF_AM    0
    
    #if DEBUG
    #define DSPRINTF(cope,mesg,arg...)    if(cope)printf(mesg,##arg);else 
    #define DFOPEN(cope,file,filename,arg)    if(cope)file=fopen(filename,arg);else 
    #define DFPRINTF(cope,file,mesg,arg...)    if(cope)fprintf(file,mesg,##arg);else
    #define DFCLOSE(cope,file)    if(cope)fclose(file);else 
    #else//DEBUG
    #define DSPRINTF(cope,mesg,arg...)
    #define DFOPEN(cope,file,filename,arg)
    #define DFPRINTF(cope,file,mesg,arg...)
    #define DFCLOSE(cope,file)
    #endif
    #endif//_LOGS_H_

    logs.c

    #include "logs.h"
    #include <pthread.h>
    
    void *thread_routine(void *arg)
    {
        int i;
        FILE *threadfile;
        DFOPEN(_LTF_AM,threadfile,"filet","a");
    #if _LTF_AM
        for(i=0;i<5;++i)
        {
            DFPRINTF(_LTF_AM,threadfile,"%d\n",i);
        }
    #endif
        DFPRINTF(_LTF_AM,threadfile,"thread end\n");
        DFPRINTF(_LTF_AM,threadfile,"%d\n",1);
        DFPRINTF(_LTF_AM,threadfile,"%d+%d=%d\n",1,2,3);
        DFCLOSE(_LTF_AM,threadfile);
    }
    
    int main()
    {
        int a=1;
        if(a==1)
            DSPRINTF(_LTS_AM,"Hello\n");
        else
            printf("error!\n");
        DSPRINTF(_LTS_AM,"%d\n",1);
        DSPRINTF(_LTS_AM,"%d+%d=%d\n\n",1,2,3);
        pthread_t id;
        int i;
        FILE *mainfile;
        pthread_create(&id,NULL,thread_routine,NULL);
        DFOPEN(_LTF_AM,mainfile,"filem","a");
    #if _LTF_AM
        for(i=0;i<5;++i)
        {
            DFPRINTF(_LTF_AM,mainfile,"%d\n",i+1);
        }
    #endif
        DFPRINTF(_LTF_AM,mainfile,"main end\n");
        DFPRINTF(_LTF_AM,mainfile,"%d\n",1);
        DFPRINTF(_LTF_AM,mainfile,"%d+%d=%d\n",1,2,3);
        DFCLOSE(_LTF_AM,mainfile);
        pthread_join(id,NULL);
        printf("end.\n");
        return 0;
    }
  • 相关阅读:
    高精度乘法
    使用BFG清除git仓库中的隐私文件或大文件
    java运行的问题
    eclipse编写的java程序在dos环境下运行的写法
    win32汇编实现阶乘和斐波那契数列
    十个数字不同,实现加减乘。暴力枚举法
    实现一个类模板
    循环队列类模板和函数模板c++实例
    C++析构函数为什么要为虚函数
    1012-Joseph 约瑟夫问题
  • 原文地址:https://www.cnblogs.com/NoSoul/p/3008409.html
Copyright © 2020-2023  润新知