Why should I always enable compiler warnings?

后端 未结 20 1915
时光说笑
时光说笑 2020-11-22 00:28

I often hear that when compiling C and C++ programs I should \"always enable compiler warnings\". Why is this necessary? How do I do that?

Sometimes I also hear tha

20条回答
  •  一个人的身影
    2020-11-22 01:04

    There's only one problem with treating warnings as errors: When you're using code coming from other sources (e.g., micro$**t libraries, open source projects), they didn't do their job right, and compiling their code generates tons of warnings.

    I always write my code so it doesn't generate any warnings or errors, and clean it up until it compiles without generating any extraneous noise. The garbage I have to work with appalls me, and I'm astounded when I have to build a big project and watch a stream of warnings go by where the compilation should only be announcing which files it processed.

    I also document my code because I know the real lifetime cost of software comes mostly from maintenance, not from writing it initially, but that's a different story...

提交回复
热议问题