UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

14.12.  The compiler errors and warnings

The compiler is the program that, given a set of code files, translates them to generate a file ready to be executed. But for this translation to be possible, the program must comply with a set of requirements imposed by the programming language. The type of checks done during this translation depends both on the programming language and the compiler itself. When a construction not allowed by the programming language is detected, the translation is stopped and a message is shown.

These messages do not explain the cause that produced them, but the low level anomaly detected by the compiler. For this reason, it is sometimes difficult to identify the true reason behind a compiler error.

14.12.1.  Errors and warnings

The C programming language is defined such that numerous decisions are taken by the compiler automatically when no information is found in the code. In other words, the compiler takes decisions about how to translate the code that the programmer has not written in the code. This, in some cases, is convenient because the programs can be written more succinctly, but only expert programmers take advantage of this feature. The recommendation is to use an option for the compiler to notify all those cases where there are implicit decisions. For the gcc compiler, this option is -Wall.

The compiler shows two types of anomalies: errors and warnings. An error is a condition that prevents the creation of a final program. No executable is obtained until all the errors have been corrected. The first errors shown are the most reliable because the translation is finished but there are some errors that may derive from previous ones. Thus, if the first errors are fixed, it is recommended to compile again and see if other later errors also disappeared.

Warnings are messages that the compiler shows about special situations in which an anomaly has been detected, but making some assumptions, the translation may proceed. Thus, a compilation does not finish until all errors are fixed, but the final executable program may be obtained with any number of warnings. When gaining experience in C programming and until a complex application is designed (multiple source code files), the recommendation is:

Compile always with the -Wall option and do not consider the program correct until all warnings have been eliminated.

Bibliography

[Gough05] Brian J. Gough. An Introduction to GCC. Network Theory Ltd. Copyright © 1995 Network Theory Ltd. Chapter 13. Common Error Messages .