freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "James K. Lowden" <jklowden AT freetds.org>
- To: TDS Development Group <freetds AT lists.ibiblio.org>
- Subject: [freetds] how to write C
- Date: Fri, 30 Nov 2007 19:34:51 -0500
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?
--jkl
-
[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.