# Filename and line information

From cppreference.com
< cpp‎ | preprocessor

Changes the current file name and number in the preprocessor.

### Syntax

`#line` lineno | (1) |
`#line` lineno `"`filename`"` | (2) |

### Explanation

1) Changes the current preprocessor line number to lineno. Expansions of the macro __LINE__ beyond this point will expand to lineno plus the number of actual source code lines encountered since.

2) Also changes the current preprocessor file name to filename. Expansions of the macro __FILE__ from 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.

lineno must be a sequence of at least one decimal digit (the program is ill-formed, otherwise) and is always interpreted as decimal (even if it starts with `0`).

If lineno is 0 or greater than 32767 (until C++11)2147483647 (since C++11), the behavior is undefined.

### Notes

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.

### Example

Run this code

    #include <cassert>
    #define FNAME "test.cc"
    int main()
    {
    #line 777 FNAME
            assert(2+2 == 5);
    }

Output:

    test: test.cc:777: int main(): Assertion `2+2 == 5' failed.

### See also

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/preprocessor/line&oldid=102083"