ANSI C标准中有几个标准预定义宏(也是常用的):
LINE:在源代码中插入当前源代码行号;
FILE:在源文件中插入当前源文件名;
DATE:在源文件中插入当前的编译日期
TIME:在源文件中插入当前编译时间;
STDC:当要求程序严格遵循ANSI C标准时该标识被赋值为1;
__cplusplus:当编写C++程序时该标识符被定义。
#include<stdio.h>
int main()
{
char file[16];
char func[16];
int line;
sprintf(file,__FILE__); //文件名
sprintf(func,__FUNCTION__);//函数名
printf("file=%s\n",file);
printf("func=%s\n",func);
printf("%05d\n",__LINE__);//行号
return 0;
}