[lug] C programming Q.

Bear Giles bgiles at coyotesong.com
Wed Apr 17 13:27:53 MDT 2002


> The majority have been prototype
> mismatches.  How often does a missing prototype cause serious problems on a
> given system (ignoring portability for the time being)?

One of my standard steps when starting a new contract is cleaning up the
compiler warnings.  It usually takes me about a week, and it exposes me
to most of the code.

With that in mind, I've found that missing protoypes are a significant
cause of errors.  E.g., a few years back there was a procedure that was
always called with a string and a manifest constant.  The constant was
a flag indicating what type of string was being passed.

Sounds simple enough, but in a few places the function calls grew an
additional "" parameter after the first string.  They weren't using
function prototypes so they didn't get a compile-time warning, and they
weren't using a catchall in the switch statement so they weren't getting
a runtime error.  They just dropped the occasional item on the floor....

Another common problem is trying to fit too much data into a variable.
Someone tried to save a few bytes and declared a variable "short," but
now they're trying to put more than 16 bits of data into it.  Or for
some reason they have something like:

 char string[20] = "this string will not fit into the allocated buffer";

> Not that it matters much to me either way.  Fixing these is easy for the
> most part.  It just delays me from spending time doing real development.

I think many of us would argue that *this* is the real development,
not the coding.  Any real project (excluding the vaporware common during
the bubble) spends far more time in maintenance than initial coding, and
the modest cost of this stuff during development is paid back many times
over during maintenance.

Bear



More information about the LUG mailing list