Alert: Never overlook warning


I hate to search the “real error message” in the overwhelming warning message when compiling the C code, since most of warning come from the type conversion. Today, I paid my price, 30 minutes debugging session.

The bug is in

double min_val( double* data, int size )

I test this code first, then put it into the main.c, later I refactor the code, move it to utilities.c. Everything seems fine, compiles, run. Oops, it is not fine, the result is totally wrong. I launched gdb, inserted several breakpoints, inspected variables, eventually, I found the the return value in the min_val was correct, but somehow returned incorrect value to the caller, weird.

Then, I realize that I might not declare min_val, and the compiler regards the return value is integer, instead of double. I rebuild the whole project with -Wall flag, yes, the warning message shows that there are “implicit conversion”, that is the source of bug! I would put -Wall in the CFLAGS since then.