Is it a good idea to eliminate compiler warnings?

前端 未结 14 2672
既然无缘
既然无缘 2021-02-19 01:00

In the past I\'ve worked with -Wall and other switches for gcc to eliminate every compiler warning for projects I\'ve been involved in. Similarly, in Perl, I always program wit

14条回答
  •  天命终不由人
    2021-02-19 01:38

    Yes, do so..

    Just yesterday I did that for a project at work. While removing the warnings I came about two issues that turned out to be real bugs.

    It was a C-project, and in one source the sqrt (square root) was called. I got the following warning:

    test.c:4: warning: implicit declaration of function 'sqrt'
    

    Turned out that the coder forgot to include the correct header-file and the square root was called with integer arguments, not floats. This was obviously wrong and not what he intended.

    The warning has been there for quite a while, but noone has seen it because it was lost in the other 1000 harmless warnings that just scrolled over the screen. Warnings are there for a reason.

    Btw - fixing the warnings took me like ... 4 hours ... That's nothing compared to the time it took to write all that stuff.

提交回复
热议问题