It is usually used by automatic code generation tools (such as yacc or bison ) to set the line number to the line value in the actual source file, and not in the C source file.
Thus, when you get the error message:
a += xyz; ^ No such identifier 'xyz' on line 15 of foo.y
you can see line 15 of the actual source file to see the problem.
Otherwise, it says something ridiculous, like No such identifier 'xyz' on line 1723 of foo.c , and you need to manually match this line in your auto-generated C file with the equivalent in your real file. Believe me, if you do not want to deeply engage yourself in the internal aspects of lexical and semantic analysis (or you want a brain hemorrhage), you do not want to go through the code generated by yacc ( bison can generate more pleasant code, I donβt know, but I donβt like it because I'm writing a higher level code).
It has two forms in accordance with the C99 standard:
#line 12345 #line 12345 "foo.y"
The first sets only the line number of the message, the second also changes the name of the registered file, so you may get an error in line 27 foo.y instead of foo.c
As for the "programmer, he put it solely for the sheer joy of lying to the compiler," no. We can be bent and twisted, but we are usually not malicious :-) This line was placed there by yacc or bison itself to do you a favor.
paxdiablo
source share