Is it a good idea to eliminate compiler warnings?

前端 未结 14 2674
既然无缘
既然无缘 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:27

    You should always try to have no warnings come up on a compile. That way, new warnings get attention. (My most frustrating experience ever with this was the AIX C++ compiler back in 2002, which spat out hundreds of warnings for code that wasn't even heavily templated.)

    Know what each warning means. In your case, you should have typed the standard int main() rather than the incorrect void main(void) or the clumsier int main(int argc, char **argv). Eliminate what you can, and suppress the warnings you have deemed acceptable.

    You may not want to fix every warning. As saua says, there are legacy systems where fixing warnings is downright dangerous, and complex systems like CGAL where you don't want to muck with the code either. In converting our apps to run under 64 bits, I found cases where I could eliminate a warning only with a cast, which would have potentially caused other problems. We suppressed that warning.

提交回复
热议问题