Compiler Diagnostic Messages

Compiler error and warning messages are produced to help you debug source code. You should attempt to understand what they mean, how to control them, and most importantly: never ignore them.

When building projects, compilers continue with the compilation process for as long as possible, even if they find errors in the source code. A compiler will only terminate if a fatal error is encountered or the number of errors reported becomes excessive. However, this means that one error can sometimes lead to further errors or warnings as the compiler tries to internally process bad or incomplete information. If the compiler issues many diagnostic messages, always begin working through them from the message reported first. In many cases, fixing one error will fix several others that follow.

Although it can be more difficult for a human to read, source statements in the C language can be spread over multiples lines of the source file. This is often done if the statement is very long. This can mean that errors in statements might not be detected until the compiler parser begins checking the subsequent lines of the source file. If you cannot find anything wrong with the line of code reported in a compiler message, check the line or lines of code above.

The most common example of a message which references a falsely reported line number is when there is a missing semicolon from a statement, which is typically reported as being a problem with the statement following the error. Another common mistake that can lead to errors reported in subsequent source code is an incorrectly terminated comment. Be especially mindful that a reported error might be caused by a mistake hidden in header file included earlier in the code.

If you would like to perform your own compile-time tests, you can issue warnings by using the MPLAB® XC #warning directive. (The MPLAB XC compilers also implements a #error directive.) For example:

Although your project might successfully build, do not ignore any warnings issued by the compiler. Warnings can indicate source code that will fail when it is executed. Compiler options are available to disable specific warnings if you can confirm these warnings are not relevant, but remember that warnings that are hidden are often forgotten. Instead, if a warning cannot be removed, consider justifying and documenting why it can be ignored in that circumstance.

If you are trying to debug code that is not executing correctly, try enabling all possible warning messages, in case there is an error you have missed in your source code.

Each MPLAB XC Compiler User’s Guide has an appendix which lists all the error and warning messages that can be produced, along with a description of the cause.

© 2017 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.