#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.

CategoryPreprocessor directives
KindKeyword / Statement
C standardC89 / 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 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏