Linux几个调试宏__FUNCTION__、 __TIME__ 、__LINE__、 __FILE__、 __DATA__(注意:前后都是两个下划线)
这几个宏是编译器内置的,不是在哪个头文件中包含的
直接上最简单的例子就好了,没必要多说。
测试代码:test_time.c
#include <stdio.h>
int main()
{
printf("The file is %s.\n",__FILE__);
printf("The date is %s.\n",__DATE__);
printf("The time is %s.\n",__TIME__);
printf("This is line %d.\n",__LINE__);
printf("This function is %s.\n",__FUNCTION__);
}
打印结果:
The file is test_time.c.
The date is Mar 6 2019.
The time is 13:55:25.
This is line 8.
This function is main.
我们测试会发现,编译一次,上面的时间就会变化,如果不编译,上面的信息就不会变化,这一点,我们可以在工作中确定,代码是否编译,是否对应的上。