Changes the current line number and file name in the preprocessor.
#line lineno | (1) | |
#line lineno " filename" | (2) |
__LINE__
beyond this point will expand to lineno plus the number of actual source code lines encountered since.__FILE__
beyond this point will produce filename.Any preprocessing tokens (macro constants or expressions) are permitted as arguments to #line
as long as they expand to a valid decimal integer optionally following a valid character string.
This directive is used by some automatic code generation tools which produce C++ source files from a file written in another language. In that case, #line
directives may be inserted in the generated C++ file referencing line numbers and the file name of the original (human-editable) source file.
The line number following the directive #line __LINE__
is implementation-defined (there are two possible values that __LINE__ can expand to in this case: number of endlines seen so far, or number of endlines seen so far plus the endline that ends the #line directive).
#include <assert.h> #define FNAME "test.c" int main(void) { #line 777 FNAME assert(2+2 == 5); }
Possible output:
test: test.c:777: int main(): Assertion `2+2 == 5' failed.
C++ documentation for Filename and line information |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/c/preprocessor/line