Any Tools to Catch Silly Mistakes in C Code?

后端 未结 11 2846
臣服心动
臣服心动 2021-02-20 08:11

I had a nasty typo that wasted my time and my colleague\'s time, it was something like this:

for (i = 0; i < blah; i++); // <- I had a semi-colon here, tha         


        
11条回答
  •  南旧
    南旧 (楼主)
    2021-02-20 08:57

    In addition to Lykathea's PC-Lint suggestion, you can also get better (or at least more) diagnostics if you bump up the warning level of the compiler. Something like /W4 or -Wall

    Though I'm not sure if your particular problem would have been caught with this (MS VC doesn't seem to flag it even with all warnings enabled). I think that's because it's not an uncommon idiom for for loops to be empty when the work is done as side effects of the loop control expressions.

提交回复
热议问题