Introduction
The #line directive allows you to define arbitrary line numbers for the source lines. Normally, the compiler counts lines starting at line number 1; using the #line directive, you can specify an arbitrary line number at any point. The compiler then uses that line number for subsequent counts.
Program
#includemain() { printf("A\n"); //A #line100 //H printf("B\n"); //B printf("C FILE %s LINE %d\n", __FILE__, __LINE__ );//C #line200 //K printf("D\n"); //D printf("E\n"); //E }
Explanation
-
The #line number in statement B is taken as 100 and for statement C, it is taken as 101.
-
The #line number in statement D is taken as 200 and for statement E, it is taken as 201.
-
If you introduce any error in statement B then the compiler will display the error at #line number 100.
-
C has provided two special identifiers: __FILE__ and __LINE__, which indicate the file name of the source file and the current line number, respectively.
Point to Remember
#line is used to indicate line numbers which can be used for debugging.
No comments:
Post a Comment