做用:对于__FILE__,__LINE__,__func__这样的宏,在调试程序时是颇有用的,由于你能够很容易的知道程序运行到了哪一个文件的那一行,是哪一个函数。编程
下面一个例子是打印上面这些预约义的宏的。函数
__DATE__,__FILE__,__LINE__,__TIME__,__FUNCTION__ C标准中指定了一些预约义的宏,对于编程常常会用到。下面这个表中就是一些经常用到的预约义宏。调试
__DATE_ %s_
进行预处理的日期(“Mmm dd yyyy”形式的字符串文字)字符串
__FILE__ %s
表明当前源代码文件名的字符串文字io
__LINE__ %d
表明当前源代码中的行号的整数常量编译
__TIME__ %s
源文件编译时间,格式微“hh:mm:ss”function
__FUNCTION__(__fucn__) %s
当前所在函数名class
#include <stdio.h>
#include <stdlib.h>
void why_me();
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__ );
why_me();
return 0;
}date
void why_me()
{
printf( "This function is %s\n", __func__ );
printf( "The file is %s.\n", __FILE__ );
printf( "This is line %d.\n", __LINE__ );
}file