先上一张表格,慢慢看:
able 1.1 ANSI Predefined Macros
Macro | Description |
__DATE__ | The compilation date of the current source file. The date is a string literal of the formMmm dd yyyy. The month nameMmm is the same as for dates generated by the library functionasctime declared in TIME.H. |
__FILE__ | The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks. |
__LINE__ | The line number in the current source file. The line number is a decimal integer constant. It can be altered with a#line directive. |
__STDC__ | Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. |
__TIME__ | The most recent compilation time of the current source file. The time is a string literal of the formhh:mm:ss. |
__TIMESTAMP__ | The date and time of the last modification of the current source file, expressed as a string literal in the formDdd Mmm Date hh:mm:ss yyyy, whereDdd is the abbreviated day of the week andDate is an integer from 1 to 31. |
在这稍微解释一下,不敢保证百分百准确
ANSIC标准定义了以下6种可供C语言使用的预定义宏: __LINE__ 在源代码中插入当前源代码行号 __FILE__ 在源代码中插入当前源代码文件名 __DATE__ 在源代码中插入当前编译日期〔注意和当前系统日期区别开来〕 __TIME__ 在源代码中插入当前编译时间〔注意和当前系统时间区别开来〕 __STDC__ 当要求程序严格遵循ANSIC标准时该标识符被赋值为1。
NOTE:
1、__STDC__是预定义宏。当它被定义后,编译器将按照ansic标准来编译你的c程序。
2、__LINE__ ,前后是两杠(其余亦是如此)
简单用法:
int line = __LINE__;
printf("line = %d\n",line); 或者直接 printf("__LINE__ = %d\n",__LINE__);