Subject: Re: CVS commit: src/sys/sys (protosw.h:1.39)
To: Geoff Wing <gcw@pobox.com>
From: Valeriy E. Ushakov <uwe@ptc.spbu.ru>
List: source-changes
Date: 08/28/2006 17:26:28
On Mon, Aug 28, 2006 at 13:37:41 +1000, Geoff Wing wrote:

> Yeah, I only had a problem with netinet/in_proto.c when compiling a
> kernel but I listed all with ones with empty trailing elements in
> the struct assignments,
>
> i.e.  { a, b, c, }, ...   vs  { a, b, c }, ...
>
> I guess it doesn't matter in practice since we only use gcc and gcc
> seems to elide them.  Maybe it's a change in the C language in the
> last ten or fifteen years which I just never noticed.  Seems a bit
> sloppy to me.

It's not an empty trailing element.  C99 allows the comma after the
alst element in the list of initiliazers (and also in enums).

Relevant productions from the grammar (6.7.8 Initialization) are:

  initializer:
          ...
          { initializer-list }
          { initializer-list , }

Treating comma as a terminator and is, IMO, a good practice as it reduces
"induced diffs" like the following:

-    foo
+    foo,
+    bar
};

vs.

     foo,
+    bar,
};

Change foo to something moderately complex to apreciate the fact that
you don't have to parse the -foo / +foo, to make sure it's only the
comma that is different.

PS: I hate the KNF rule that optional {} are to be omitted precisely
because of that.  Adding second statement (that makes the curlies
mandatory) introduces an induced diff on the opening line, and if that
line happens to be e.g. an "if" with a non-trivial condition you have
to waste time parsing the extra diff line to verify if it was the
curly change only.


SY, Uwe
-- 
uwe@ptc.spbu.ru                         |       Zu Grunde kommen
http://snark.ptc.spbu.ru/~uwe/          |       Ist zu Grunde gehen