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?

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.

Comments
thanks for parsing that.
This article has been dead for over six months. Start a new discussion instead.