Any Tools to Catch Silly Mistakes in C Code?

后端 未结 11 2895
臣服心动
臣服心动 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条回答
  •  梦毁少年i
    2021-02-20 08:34

    A few things that have saved me in the past, from the top of my head:

    • Use if (3 == bla) rather than (bla == 3), because if you misspell and type (3 = bla) the compiler will complain.

    • Use the all-warnings switch. Your compiler should warn you about empty statements like that.

    • Use assertions when you can and program defensively. Put good effort into making your program fail early, you will see the weaknesses that way.

    • Don't try to circumvent any safeguards the compiler or the OS have put in place. They are there for your ease of programming aswell.

提交回复
热议问题