- Normally the compiler only generates error messages about erroneous code that does not comply with the C standard, and warnings about things that usually tend to cause errors during runtime.
- However, we can usually instruct the compiler to give us even more warnings, which is useful to improve the quality of our source code, and to expose bugs that will really bug us later.
- With gcc, this is done using the "-W" flag. For example, to get the compiler to use all types of warnings it is familiar with, we'll use a command line like this:
$gcc -Wall code1.c -o code1
This will first annoy us - we'll get all sorts of warnings that might seem irrelevant.
- However, it is better to eliminate the warnings than to eliminate the usage of this flag. Usually, this option will save us more time than it will cause us to waste, and if used consistently, we will get used to coding proper code without thinking too much about it.
- One should also note that some code that works on some architecture with one compiler, might break if we use a different compiler, or a different system, to compile the code on. When developing on the first system, we'll never see these bugs, but when moving the code to a different platform, the bug will suddenly appear. Also, in many cases we eventually will want to move the code to a new system, even if we had no such intentions initially.
Cem Ozdogan
2011-02-14