{ initializer-list , }

Dave Burton daveb at laidbak.UUCP
Tue Mar 15 07:04:25 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.).

I (ab)use this syntax all the time when writing programs with a
large number of initializers. It is very useful when this list
must undergo maintenance - additions, deletions, reorganization, etc.
For example:

static char *message[] = {
	"message",
	"another message",
	"yam",
	"...",
	"etc",
};

If more messages need to be added, just tack 'em on.

It also has the potential to make automatic program generators
(a trivial amount) easier to implement.
-- 
--------------------"Well, it looked good when I wrote it"---------------------
 Verbal: Dave Burton                        Net: ...!ihnp4!laidbak!daveb
 V-MAIL: (312) 505-9100 x325            USSnail: 1901 N. Naper Blvd.
#include <disclaimer.h>                          Naperville, IL  60540



More information about the Comp.lang.c mailing list