0

I see this in KR C programming language. I really did not understand what it means. If it is line number of current source then we could use __LINE__. But what is the use of #line actually?

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
Featured Replies
  • [URL="http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/language/ref/clrc09lc.htm"]Read this link[/URL]. [quote]In order for the compiler to produce meaningful references to line numbers in preprocessed source, the preprocessor inserts #line directives where necessary (for example, at the beginning and after the end of included text). [/quote] When the preprocessor parses your *.c program it will create a *.i … Read More

1

Read this link.

In order for the compiler to produce meaningful references to line numbers in preprocessed source, the preprocessor inserts #line directives where necessary (for example, at the beginning and after the end of included text).

When the preprocessor parses your *.c program it will create a *.i file that expands all the #include and other preprocessor statements. In doing that all the include files are merged into one *.i file. When doing that it adds the #line directives so that it can keep track of the line numbers from the original file. Then when the compiler compiles the *.i file it will know the line numbers from the original files and use them to produce meaningful error messages. Without #line directives you would get line numbers from the *.i file, not the *.c or *.h file that you wrote.

I know of no reason why a programmer would want to insert #line directives in his program.

Votes + Comments
thanks for parsing that.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.