Fix all compiler warnings

This tip submitted by rickey on 2005-09-26 04:43:39. It has been viewed 14160 times.
Rating of 6.2 with 142 votes



When you're first starting out, you have no choice but to solve the errors detected by the compiler, but you might neglect the warnings given by the compiler!

Warnings are cases where the compiler understands what your program is doing, and thinks that it's probably not doing what YOU want it to do. The compiler is pretty smart, so it's usually right.

For example, with code like this:

int getMultiple(int x, int y)
{
x * y;
}

you might have warning that says, "function should return a value"


This is because you forgot to return the result of the multiplication. Many compiler warnings are similarly valuable.

In general, you should compile with as many compiler warnings as possible (-Wall on GCC for example) and fix all of them. You can force yourself to do so if you compile with -Werror on GCC, which will cause GCC to treat all warnings as errors.



More tips

Help your fellow programmers! Add a tip!