c语言预处理器的内置宏
__FILE__ 当前文件
__LINE__ 当前行
__DATE__ 当前日期
__TIME__ 当前时间
且看下面的例子
//test.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
#ifdef DEBUG
printf(“Compiled: “ __DATE__ “ at “ __TIME__ “\n”);
printf(“This is line %d of file %s\n”, __LINE__, __FILE__);
#endif
printf(“hello world\n”);
exit(0);
}
设置DEBUG编译
gcc -DDEBUG -o test test.c
./test
显示如下结果
Compiled: Nov 29 2012 at 23:49:34
This is line 7 of file cinfo.c
hello world