Is it a good idea to eliminate compiler warnings?

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

    Yes. Even the trivial ones are worth fixing. Here's why. Some, like the example of main you mention, probably aren't worth fixing on their own, but they are in aggregate. Most compiler warnings will save you direct pain in the long term. They are bugs waiting to happen (or even happening now). In order to find those, you need an easy way to notice them. If you fix all of the warnings, then each new warning is a red flag and easy to notice. If you fix all of the critical ones but leave some like the "main" issue alone, you will miss the new critical ones.

    Which is easier to remember? That any warning needs to be fixed or that you had 23 irrelevant warnings in this code base yesterday and so if you see 24 you need to go take a look?

    In the code base I work on we tell the compiler to generate errors on all warnings. This forces us to fix them and keeps the code in much better shape. If there's ever a warning that truly isn't worth fixing, there is always #pragma to make it disappear. That way you still have a bright line for failure.

提交回复
热议问题