在C的调试中,有几个宏经常被使用来辅助程序员进行程序调试,这里对之进行简单介绍。
1、__FUNCTION__
该宏被用来表示调用该宏的函数。
2、__LINE__
该宏用来表示调用该宏的对应行数。
3、__TIME__
该宏用来表示调用该宏时的时间。
4、__DATE__
该宏用来表示调用该宏的日期。
5 、__FILE__
该宏用来表示调用该宏的文件。
示例程序:
# include <stdio.h>
#include <math.h>
void test(void)
{
printf("the file is %s\n", __FILE__);
printf("the date is %s\n", __DATE__);
printf("the time is %s\n", __TIME__);
printf("the line is %d\n", __LINE__);
printf("the function is %s\n", __FUNCTION__);
return ;
}
int main()
{
test();
return 0;
}
也可以通过宏定义的方式来使用上述的宏: