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
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.
A good syntax highlighter will make some cases like this more visible.
Also look at clang static analysis
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.
Yes, PC-Lint is probably the best tool available.