How does a compiler tie an error message back to the source code?

Usually we see (C++/.NET) programs throwing exception messages which are not very informative. But at-least they direct me to the line from where the problem originated. How does the compiler do that?

Compilers have two modes when building a program – DEBUG & RELEASE.

By default, compiler builds the program in the debug mode & adds line-number information that maps the lines in source code to the corresponding lines of machine code. For example, the map might say that line 200 of machine code in the executable code was created from the C++ source code on line 16.

This debug information consumes a lot of space & it makes the executable file larger & slower. To address this problem, the compiler also has a release mode in which the debug information is stripped out.

leave your comment