# Alert: Never overlook warning

cpp

I hate to search the “real error message” in the overwelming 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, insert serveal breakpoints, inspect variables, eventually, I find the return value of callee side, i.e min_value is right, but the value in the caller side is wrong. It is kind weired…

Then, I realize that I might not declare min_val, and the compiler regards the return value is integer, instead of double. Then 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.