本文共 601 字,大约阅读时间需要 2 分钟。
ANSI C标准中有几个标准预定义宏:__FILE__ __DATE__ __TIME___ __LINE__ 等
__LINE__:在源代码中插入当前源代码行号;
__FILE__:在源文件中插入当前源文件名;
__DATE__:在源文件中插入当前的编译日期
__TIME__:在源文件中插入当前编译时间;
__STDC__:当要求程序严格遵循ANSI C标准时该标识被赋值为1;
__cplusplus:当编写C++程序时该标识符被定义。
这几个宏比较有用~~~~~~~~
在调试程序时或编译时,__LINE__比较有用,可以用来打印逻辑错误的行号~~~~~~~,例子:
switch(x)
{
1:
....;
break;
case 2:
.....;
break;
default:
printf("logic erro line number%d!/n",__LINE__);
break;
}
又如用__DATE__和__TIME__可以插入编译时间。
代码:
void print_version_info(void)
{
printf("Date Compiled:%s/n",__DATE__);
printf("TimeCompiled:%s/n",__TIME__);
}
输出格式为:mm dd yy 和 hh:mm:ss
这样可以做到版本,自己也很清楚自己什么时候编译过~~
转载地址:http://jbsqi.baihongyu.com/