I think it would be great if there was a way to easily capture my "most common error categories".
Years ago I got bit a couple of times by assignment instead of comparison errors (i.e. if(x = 1) instead of if(x == 1))
I noticed a pattern and made a conscious to always put the variable last in comparisons, so for years I have written if(1==x) so that the compile would fail if I wrote if(1=x).
Having a way to see my most common errors would give the opportunity to look for similar error-proofing measures.
I have seen this practice refered to as "Yoda conditionals" but never knew the reason for it. Although it reads wrongly (to me), I can now see the logic.
A lot of the code I write is JavaScript in Aptana, which has a real-time JSLint checker that warns against assignments in conditionals.
You forgot "-pedantic" and "-Wextra". =P (And possibly a few more one-offs that aren't contained in the groups.) Though the key flag there to make it warn is -Wall, so you can still compile with c99 and avoid the -ansi flag.
Pretty much any compiler or language worth its salt that allows assignment in conditionals with the equals sign (so Python, Lisp are out) will warn you about it.
Comments
I think it would be great if there was a way to easily capture my "most common error categories".
Years ago I got bit a couple of times by assignment instead of comparison errors (i.e. if(x = 1) instead of if(x == 1))
I noticed a pattern and made a conscious to always put the variable last in comparisons, so for years I have written if(1==x) so that the compile would fail if I wrote if(1=x).
Having a way to see my most common errors would give the opportunity to look for similar error-proofing measures.
I have seen this practice refered to as "Yoda conditionals" but never knew the reason for it. Although it reads wrongly (to me), I can now see the logic.
A lot of the code I write is JavaScript in Aptana, which has a real-time JSLint checker that warns against assignments in conditionals.
I have never heard it called "Yoda conditionals" before. That is awesome.
I always compile C code this way, so it warns me about that particular type of error:
You may not have to use all of those options, I'm not sure. The error message is: I find that very helpful.You forgot "-pedantic" and "-Wextra". =P (And possibly a few more one-offs that aren't contained in the groups.) Though the key flag there to make it warn is -Wall, so you can still compile with c99 and avoid the -ansi flag.
Pretty much any compiler or language worth its salt that allows assignment in conditionals with the equals sign (so Python, Lisp are out) will warn you about it.
That is quite interesting.
So, have you stopped using assignments instead of comparison operators, or does the compiler just prevent you from writing a logic error?