调试时打印运行代码所在源文件、行号、函数名

来源:互联网 发布:js获取input的长度 编辑:程序博客网 时间:2024/04/29 10:56

使用宏

__FILE__               文件名

__LINE__               行号

__FUNCTION__      函数名

即可。

 

 

#include <stdio.h>

void my_free(void *p,const char* file,const char* fun,int line)
{
   
if(p != NULL)
    {
        puts(
"current file and function:");
        puts(__FILE__);
        puts(__FUNCTION__);
        printf(
"line:%d/n", __LINE__);
        puts(
"error frome file and function:");
        puts(file);
        puts(fun);
        printf(
"line:%d/n", line);
    }
   
else
    {
       
//free(p);
       
//free_count++;
    }
}

int main(void)
{
   
char* s="afg";
    my_free(s,__FILE__,__FUNCTION__,__LINE__);
    getchar();
   
return 0;
}

原创粉丝点击