#line指令用于改变 the contents of __line__ and __file__.
Both __line__ and __file__ are predefined identifiers in the compiler, where the content of the identifier __line__ is the line number of the currently compiled line of code, and the __file__ content is the file name of the currently compiled source file.
#line的一般形式是: #line number "filename"
Where number is a positive integer and becomes the new value of __line__; the optional "filename" is the legal file identifier and becomes the new value of the __file__.
#line主要用于调试和特殊应用.
#line的使用实例:
1#include <stdio.h>2 #line"NewFileName"3 intMain ()//From here the number is4{//2015printf"%s\n", __file__);//#line重命名文件为NewFileName6printf"%d\n", __line__);//line number is 2037printf"%d\n", __line__);//2048printf"%d\n", __line__);//2059 return 0;Ten}
The result of the operation is:
NewFileName 203 204 205
Note: __date__: Used to record the date the source file was compiled into an executable file __time__: Used to record when the source file was compiled into an executable __stdc__: Indicates whether the compiler uses ANSI C standard viewing: printf ("%s\n", __date_ _);//Date the file was compiled
printf ("%s\n", __time__);//time to compile the file
printf ("%d\n", __stdc__);//Indicates whether the compiler uses ANSI C standards
The #line in C language