
Best practices for programming in C - twampss
http://www.ibm.com/developerworks/aix/library/au-hook_duttaC.html
======
silentbicycle
"Errors cannot be avoided by recipe. If they could, we could eliminate
automobile accidents by plastering the countryside with _Drive Carefully_
signs!" -- Andrew Koenig, _C Traps and Pitfalls_

Some of the article's examples come straight from that book, BTW.

~~~
smhinsey
is that quote meant seriously? certainly it's obvious that the analogy doesn't
work. we do have signs plastered around the countryside that are recipes for
driving, they just actually include the ingredients. i would think the same
applies to code, but rather than recipes, to hold the analogy, you are
providing templates for recipes, or maybe style guides for writing recipes.
(bad analogy, imho.)

~~~
silentbicycle
More like listing mistakes to watch for. I was mostly posting to note that the
book was a much more in-depth collection of same.

------
jonke
This is like a never ending issue. One way to start the path to a better
practice of C is to read [http://www.amazon.com/Expert-Programming-Peter-van-
Linden/dp...](http://www.amazon.com/Expert-Programming-Peter-van-
Linden/dp/0131774298) after you finished [http://www.amazon.com/Programming-
Language-Prentice-Hall-Sof...](http://www.amazon.com/Programming-Language-
Prentice-Hall-Software/dp/0131103628)

------
saucetenuto
"Since function calls usually take a long time, getchar is often implemented
as a macro." And then I stopped reading. Does anyone know of a meaning for
this sentence that's more sophisticated than "function call overhead is
punishing, don't call functions if you can help it", advice that was out of
date when C was /invented/, for God's sake? Something special about getchar(),
maybe?

~~~
visitor4rmindia
Um...function calls _do_ have an overhead. Yes it is negligible in most cases
but it certainly made a difference when C was invented.

In fact, C++ still carries the "inline" declaration around to avoid function
call overhead. The compiler can ignore when knows better but the fact that
inlining exits implies that function call overhead is not imaginary.

------
philwelch
I like how gets() and scanf() are both considered unsuitable for use. There's
something wrong with a language when you can't trust the standard library's
input functions, and I say this as someone who rather likes C in the right
context.

Where's the mention of the three-argument main() variation? (int argc, char
__argv, char __env)? Is this not standard?

------
sb
just for the record: i always found rob pike's advice on c programming very
thoughtful and readable (and, common: he should know ;)

<http://www.lysator.liu.se/c/pikestyle.html>

------
windsurfer

      C; I <3* u;

