UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

14.2.  Showing all the warnings

Contrary to other compilers such as the one for Java, the C compiler does not check exhaustively that a program strictly complies with the language definition. When certain aspects are omitted in a C program, the compiler assumes some behavior by default and the executable is generated anyway. But this policy is dangerous if the programmer is not fully aware of these behaviors assumed by the compiler. For this reason the option -W followed by the type of checks that should be performed is offered by the compiler.

Delete the executable from the directory. Compile again the previous program but this time requesting that all warnings are shown with the following command:

$ gcc -Wall -o main_en main_en.c

You see that, although the program has not changed, the compiler now shows some warnings and the executable file has been generated anyway. In this case, the program behaves exactly as expected, but every warning shown by the compiler is about some aspect of the code that is not perfectly stated, and therefore may have consequences during execution. Read carefully the warning messages and modify the code such that they disappear. Do not make random changes in the code, you will not know the exact cause for the warning.

We recommend that every compilation you execute in the course you include the -Wall option. We will do so when assessing the quality of your code.