Why should I always enable compiler warnings?

后端 未结 20 1569
时光说笑
时光说笑 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 00:58

    COMPILER WARNINGS ARE YOUR FRIEND (not shouting, uppercase for emphasis).

    I work on legacy Fortran-77 systems. The compiler tells me valuable things: argument datatype mismatches on a subroutine call, using a local variable before a value has been set into the variable, if I have a variable or subroutine argument that is not used. These are almost always errors.

    Avoiding a long post: When my code compiles cleanly, 97% it works. The other guy I work with compiles with all warnings off, spends hours or days in the debugger, then asks me to help. I just compile his code with the warnings on and tell him what to fix.

提交回复
热议问题