freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: christos AT zoulas.com (Christos Zoulas)
- To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
- Subject: Re: [freetds] how to write C
- Date: Fri, 30 Nov 2007 21:27:08 -0500
On Nov 30, 7:34pm, jklowden AT freetds.org ("James K. Lowden") wrote:
-- Subject: [freetds] how to write C
| I have an opinion I want to check with the old hands out there, because
| the GNU C compiler issues a warning I think should be ignored.
|
| Given code like this:
|
| if (a && b || c && d)
| /* ... */
|
| the compiler "recommends" parentheses, encouraging:
|
| if ((a && b) || (c && d))
| /* ... */
|
| Please. To he who would read the code, I say RTFM. If K&R is too long
| for you, here's a short version:
|
| $ man operator | grep -E '&&|\|\|'
| && left to right
| || left to right
|
| That's all you need to know.
|
| The FreeTDS code is loaded with deeply nested structures of pointers,
| state maintenace, portability considerations. Confusion is an ever
| present threat, and confusion about C is surely the least of our concerns.
|
|
| If you need examples of subtle things the compiler *won't* find that *are*
| harmful:
|
|
| if((ret=func() != NULL))
| instead of
| if((ret=func()) != NULL)
|
| is a good one. I fixed one like that last week. So is:
|
| memset( ptr, len, '\0')
|
| a favorite of mine, not least because '\0' is silly: the value argument is
| defined as int.
|
| Am I missing something? Are there compilers out there that would get this
| wrong? Do the parentheses give the compiler information it doesn't
| otherwise have? Or is this just nanny nagging we can turn off by default?
|
What's the cost of fixing the compiler warnings? Is it better to ignore
them? I think that making the base code compiling cleanly and forcing
contributors to write code that does not produce warnings has been
proven to be a good practice for me. So turn on all the warnings you
can in the default compilation environment, and make people who contribute
code wrire code that is warning free. These warnings clarify the programmers
intent, so it is always best to see them.
christos
-
[freetds] how to write C,
James K. Lowden, 11/30/2007
- Re: [freetds] how to write C, entropy, 11/30/2007
- Re: [freetds] how to write C, Christos Zoulas, 11/30/2007
Archive powered by MHonArc 2.6.24.