Any Tools to Catch Silly Mistakes in C Code?

后端 未结 11 2888
臣服心动
臣服心动 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:48

    I would start by learning about splint and gdb. If you need more advanced, build on these two tools. But they are a good start.

    0 讨论(0)
  • 2021-02-20 08:51

    A good syntax highlighter will make some cases like this more visible.

    0 讨论(0)
  • 2021-02-20 08:52

    Also look at clang static analysis

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-20 08:59

    Yes, PC-Lint is probably the best tool available.

    0 讨论(0)
提交回复
热议问题