看<<C intefaces and implementations>>时看到__FILE__与__LINE__,不甚理解,于是乎查了下。
__FILE__与__LINE__是预定义的宏,实现了标准的编译器中均可使用这些宏
__FILE__宏输出的是当前输入文件的路径,含文件名,而__LINE__宏输出当前代码所在的行号(整数变量)
以下文字部分引用自http://gcc.gnu.org/onlinedocs/cpp/Standard-Predefined-Macros.html
-
This macro expands to the name of the current input file, in the form of a C string constant. This is the path by which the preprocessor opened the file, not the short name specified in `
#include' or as the input file name argument. For example,
"/usr/local/include/myheader.h"
is a possible expansion of this macro.
- This macro expands to the current input line number, in the form of a decimal integer constant. While we call it a predefined macro, it's a pretty strange macro, since its “definition” changes with each new line of source code.
__FILE__
__LINE__
__FILE__
and __LINE__
are useful in generating an error message to report an inconsistency detected by the program; the message can state the source line at which the inconsistency was detected. For example,
fprintf (stderr, "Internal error: " "negative string length " "%d at %s, line %d.", length, __FILE__, __LINE__);
#include<stdio.h>
int main(){
printf("%s\n",__FILE__);
printf("%d\n",__LINE__);
return 0;
}