#line Change the presumed line number and file name
#line Change the presumed line number and file name
#line sets presumed line numbers and optional file names for later source, affecting __LINE__, __FILE__, and diagnostics without renaming files on disk.
| Category | Preprocessor directives |
|---|---|
| Kind | Keyword / Statement |
| C standard | C89 / C90 |
📝 Syntax
#line line-number
#line line-number "file-name"
▶ Example
Edit the C code below and click Run; the server compiles and executes it:
Output:
line = 100
next = 101
file = example.c
ℹ️ Info The new numbering starts with the source line immediately after #line, so the first __LINE__ is 100 and the next is 101. The presumed name is explicitly set to example.c and does not depend on the editor's actual file name.
💡 Tip #line changes only the presumed location; it neither renames a file on disk nor changes program control flow. It is mainly used by tools such as code generators to map diagnostic locations.
🏷️ Related preprocessor directives
📚 Related Tutorials
❓ FAQ
QWhy does __LINE__ print 100 after #line 100?
AThe number applies to the source line immediately following the directive, not to the line containing #line itself. The presumed number then increments normally on subsequent lines.
QDoes #line rename the actual file?
ANo. The file-name form changes only the presumed name used by __FILE__ and diagnostics. It does not access, create, or rename a file on disk.
QWhy is #line often used by code generators?
AA generator can map locations in generated C back to the original template or specification, so compiler diagnostics, __LINE__, and __FILE__ point to the source the user actually needs to edit. It changes only presumed line numbers and file names; it does not move generated code or rename files on disk.