Is it a good idea to eliminate compiler warnings?

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

    Your example is a perfect illustration why warnings shouldn't be ignored. void main(void) is an invalid prototype (but int main(void) works!)) and your code may break on some compilers. Your compiler was nice enough to point this out.

    I've found that almost every warning actually pointed to a real problem, even if I failed to understand the cause at the time. Basically, I always did something and intended something else. The effect might have been achieved anyway, but only by pure coincidence.

    Treat warnings as errors. Exceptions exist (there's one in the VB.NET compiler concerning uninitialized value types) but are exceedingly rare. And if you ever stumble upon one of these exceptions, you'll know it.

提交回复
热议问题