What is #line used for?
The #line preprocessor directive is used to reset the values of the _ _LINE_ _ and _ _FILE_ _ symbols,
respectively. This directive is commonly used in fourth-generation languages that generate C language source
files. For instance, if you are using a fourth-generation language named “X,” the 4GL compiler will generate
C source code routines for compilation based on your 4GL source code. If errors are present in your 4GL
code, they can be mapped back to your 4GL source code by using the #line directive. The 4GL code
generator simply inserts a line like this into the generated C source:
respectively. This directive is commonly used in fourth-generation languages that generate C language source
files. For instance, if you are using a fourth-generation language named “X,” the 4GL compiler will generate
C source code routines for compilation based on your 4GL source code. If errors are present in your 4GL
code, they can be mapped back to your 4GL source code by using the #line directive. The 4GL code
generator simply inserts a line like this into the generated C source:
#line 752, “XSOURCE.X”
void generated_code(void)
{
...
}
Now, if an error is detected anywhere in the generated_code() function, it can be mapped back to the
original 4GL source file named XSOURCE.X. This way, the 4GL compiler can report the 4GL source code
line that has the error in it.
When the #line directive is used, the _ _LINE_ _ symbol is reset to the first argument after the #line keyword
(in the preceding example, 752), and the _ _FILE_ _ symbol is reset to the second argument after the #line
keyword (in the preceding example, “XSOURCE.X”). All references hereafter to the _ _LINE_ _ and _ _FILE_ _
symbols will reflect the reset values and not the original values of _ _LINE_ _ and _ _FILE_ _
Cross Reference:
V.2: What will the preprocessor do for a program?
V.22: What is a pragma?
No comments:
Post a Comment