在编程时,有时需要知道当前的代码是在第几行,当前文件名是什么,以及当前执行的是哪个函数?下面的代码可以轻松地完成这种功能:
#include <stdio.h>
void test()
{
printf("Line:%d, File:%s, Function:%s\n", __LINE__, __FILE__, __FUNCTION__);
}
int main()
{
printf("Line:%d, File:%s, Function:%s\n", __LINE__, __FILE__, __FUNCTION__);
test();
return 0;
}
运行结果:
Line:10, File:t.c, Function:main
Line:5, File:t.c, Function:test