3.6.2 How Do I Find the Code that Caused Compiler Errors or Warnings in My Program?

In most instances, when a syntax error occurs that relates to the source code, the message produced by the compiler indicates the offending line of code (see 4.5.1 Messaging Overview). If you are compiling in MPLAB X IDE, then you can double-click the message and have the editor take you to the offending line. But identifying the offending code is not always so easy.

In some instances, the error is reported on the line of code following the line that needs attention. This is because a C statement is allowed to extend over multiple lines of the source file. It is possible that the compiler cannot be able to determine that there is an error until it has started to scan to statement following. So in the following code

input = PORTB   // oops - forgot the semicolon
if(input>6)
// ...

The missing semicolon on the assignment statement will be flagged on the following line that contains the if() statement.

In other cases, the error might come from the assembler, not the code generator. If the assembly code was derived from a C source file, then the compiler will try to indicate the line in the C source file that corresponds to the assembly that is at fault. If the source being compiled is an assembly module, the error directly indicates the line of assembly that triggered the error. In either case, remember that the information in the error relates to some problem in the assembly code, not the C code.

Finally, there are errors that do not relate to any particular line of code at all. An error in a compiler option or a linker error are examples of these. If the program defines too many variables, there is no one particular line of code that is at fault; the program as a whole uses too much data. Note that the name and line number of the last processed file and source can be printed in some situations even though that code is not the direct source of the error.

To determine the application that generated the error or warning, check the message section of the manual, see 10 Error and Warning Messages. At the top of each message description, on the right in brackets, is the name of the application that produced this message. Knowing the application that produced the error makes it easier to track down the problem. The compiler application names are indicated in 4.2 The Compilation Sequence. If you need to see the assembly code generated by the compiler, look in the assembly list file (see 6.3 Assembly List Files). For information on where the linker attempted to position objects, see the map file discussed in 7.3 Map Files.