This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: Question regarding bizarre ','
- From: Michael Snyder <msnyder at redhat dot com>
- To: Daniel Jacobowitz <drow at mvista dot com>
- Cc: Joel Brobecker <brobecker at gnat dot com>, gdb-patches at sources dot redhat dot com
- Date: Mon, 05 Aug 2002 18:20:31 -0700
- Subject: Re: Question regarding bizarre ','
- Organization: Red Hat, Inc.
- References: <20020806012134.GC916@gnat.com> <20020806012702.GA15122@nevyn.them.org>
Daniel Jacobowitz wrote:
>
> On Mon, Aug 05, 2002 at 06:21:35PM -0700, Joel Brobecker wrote:
> > This is where I show my lack of C-knowledge:
> >
> > in i386v4-nat.c, I read the following code:
> >
> > /* Mapping between the general-purpose registers in `/proc'
> > format and GDB's register array layout. */
> > static int regmap[] =
> > {
> > EAX, ECX, EDX, EBX,
> > UESP, EBP, ESI, EDI,
> > EIP, EFL, CS, SS,
> > DS, ES, FS, GS,
> > };
> >
> > I would have thought that the last ',' would cause a compilation error.
> > But this seems to compile fine. Any reason for keeping this last comma?
>
> It makes it easier to add an element without having to touch any
> existing line, to make diffs clearer. A trailing comma in an array
> initializer (or struct initializer maybe?) is ignored.
By most compilers, but some (possibly deviant ones) will give you
an error, or at least a warning. I have definitely encountered this
when building GDB, and I think most array and enum initializers in
gdb do not have the trailing comma for this reason.
Michael