Page 2 of 2
Posted: Mon Dec 11, 2006 11:05 am
by Candy
Solar wrote:Brynet-Inc wrote:And then you could turn on the -pedantic (or -pedantic-errors) flag...
Note that "-pedantic" does not refer to "pedantic error-checking" but rather "pedantic adherence to what the standard says". At some points the standard requires a diagnostic where "GNU style" doesn't, and vice versa.
Pedantic stuff is warning about unused variables, unused parameters with a name (yes), in some standard forms not declaring a function with an empty parameter list as (void) but as (), stuff like that. The stuff just about nobody commonly thinks should be considered wrong, but really is.
Solar, I see a long list of possible warnings but no -Wextra. Any reason for that?
Posted: Mon Dec 11, 2006 4:26 pm
by Solar
Candy wrote:Solar, I see a long list of possible warnings but no -Wextra. Any reason for that?
Uh... I'm sure I had one, but can't really remember at the moment...
Posted: Wed Dec 13, 2006 2:55 am
by Solar
I checked... indeed I overlooked -Wextra. Adding it led to several "unused parameter" warnings where I had added a function stub but didn't implement it yet (so I disabled that particular warning class for now), and three "comparing signed to unsigned" warnings that were easily fixed - revealing, however, a genuine bug in my printf() code.
Point in case. Warnings are a good thing.
Posted: Wed Dec 13, 2006 10:47 am
by Candy
I am thinking that -Wextra includes the list of warnings you explicitly turn on. My common warning list is:
Code: Select all
-Wall -Wextra -Werror -pedantic -pedantic-errors -std=gnu++98
If I could've set it to gnu++03 or 0x I would. This cleans up your code to not include stuff that could be pretty vague and to mostly keep a clean style. It forbids a number of "wrong" constructs.
I am not claiming that this produces good code. I am claiming that this changes a proper and consistent style into proper, consistent and readable code. You could make an IOCCC submission with these items, but if applied to properly formatted coding fishes out 99% of all mistakes.
If you learn to avoid the complex mistakes you can let the compiler complain about the rest. I can proudly claim that 90% of my mistakes are caught by the compiler, 8% by me during coding (but eh... that's impossible) and 2% during testing (where something doesn't crash, flaw, but just does the wrong thing). Code that does something can be changed to do another thing. Code that doesn't stably do something can't.
Just for fun, try the above flags with "make -k" and count the errors. All of these errors could and can be problems in your code.
Posted: Thu Dec 14, 2006 1:45 am
by Solar
Candy wrote:I am thinking that -Wextra includes the list of warnings you explicitly turn on.
Nope.
Check 'info gcc', Warning options.