[lug] C programming Q.

Bear Giles bgiles at coyotesong.com
Wed Apr 17 11:41:01 MDT 2002


> On Wed, Apr 17, 2002 at 11:54:41AM -0500, Michael J. Hammel wrote:
> > I hate this.  We're using some gawd-awful args to gcc that force all
> > warnings into errors so compiles fail.  Ick.  
> 
> No, this is a _good_ habbit, really ;-) Since i made this the default
> in my projects (and cranked up the warning switches) i had way less 
> bugs sneak into my production code.

I dislike the forced warnings->errors coercion for two reasons.
First, there are some rare situations where you can't easy eliminate
the warnings.  These are very rare, maybe only once every 10 kloc, but 
like gotos when you need them you really need them.

Second, as a practical matter this coercion usually ends up driving
junior programmers into quick fixes that eliminate the warning, not
the problem.  E.g., they'll use a cast to coerce an argument into
the "expected" type, instead of figuring out why the procedure and
arguments aren't in sync.  Not only does this leave the bug in the code,
it makes it far harder for someone to find the bug in the future.

But I agree with you - turning on all compiler warnings really 
cleans up the code because it eliminates several classes of stupid
coding errors.  It's especially powerful when combined with assertions
implementing programming-by-contract checks and checking for off-by-one
errors.  Bugs can still slip by, but they're usually design errors
instead of implementation errors.  That is, you're correctly doing
the wrong thing, instead of incorrectly doing something.

Bear



More information about the LUG mailing list