{ initializer-list , }
Richard Harter
g-rh at cca.CCA.COM
Mon Mar 14 15:44:19 AEST 1988
In article <660 at kuling.UUCP> bjornc at kuling.UUCP (Bj|rn Carlsson) writes:
>Why is an optional trailing comma inside the braces after an initializer-list
>allowed? Since it doesn't affect the meaning of the initializer we can't
>see any other reasons for including it except historical. Is it included
>in the Draft proposed ANSI C? We are currently writing a compiler for a
>subset of C and got a bit confused when finding this strange syntax.
>It is documented in both K&R and Harbison&Steele (2nd ed.).
This is one of those little things that makes life a little nicer for
people who have to maintain code. Suppose you have a table of records,
with one item per line, all nicely aligned in columns for readibility.
Suppose you want to add a new record; you may enter a new record with
out altering the line for the old record -- your code control rev history
will be cleaner. Again, suppose that your table of initializers is machine
generated; the generator code will be simpler if the last item is not a
special case. Indeed, if you think about it, the specification is simpler
if the comma is a terminator rather than a separator because all items in
the specification list have the same format, instead of the last one having
a special format.
C's use of the semicolon is analogous; C uses a semicolon as a statement
termninator rather than as a separator as in Algol and Pascal. In that
case human factors studies have found that the C treatment is superior
to the Algol treatment -- fewer semicolon errors are made when the C
style is used than when the Algol style is used.
--
In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
Richard Harter, SMDS Inc.
More information about the Comp.lang.c
mailing list