* Question regarding bizarre ','
@ 2002-08-05 18:21 Joel Brobecker
2002-08-05 18:26 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Joel Brobecker @ 2002-08-05 18:21 UTC (permalink / raw)
To: gdb-patches
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?
Thanks,
--
Joel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question regarding bizarre ','
2002-08-05 18:21 Question regarding bizarre ',' Joel Brobecker
@ 2002-08-05 18:26 ` Daniel Jacobowitz
2002-08-05 18:39 ` Michael Snyder
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2002-08-05 18:26 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
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.
--
Daniel Jacobowitz Carnegie Mellon University
MontaVista Software Debian GNU/Linux Developer
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question regarding bizarre ','
2002-08-05 18:26 ` Daniel Jacobowitz
@ 2002-08-05 18:39 ` Michael Snyder
2002-08-05 19:20 ` Andrew Cagney
0 siblings, 1 reply; 6+ messages in thread
From: Michael Snyder @ 2002-08-05 18:39 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: Joel Brobecker, gdb-patches
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question regarding bizarre ','
2002-08-05 18:39 ` Michael Snyder
@ 2002-08-05 19:20 ` Andrew Cagney
2002-08-06 16:15 ` Kevin Buettner
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2002-08-05 19:20 UTC (permalink / raw)
To: Michael Snyder; +Cc: Daniel Jacobowitz, Joel Brobecker, gdb-patches
> 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.
This is true of enums (cf the alpha compiler) but not, I believe, of
array initializers.
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question regarding bizarre ','
2002-08-05 19:20 ` Andrew Cagney
@ 2002-08-06 16:15 ` Kevin Buettner
2002-08-06 16:44 ` david carlton
0 siblings, 1 reply; 6+ messages in thread
From: Kevin Buettner @ 2002-08-06 16:15 UTC (permalink / raw)
To: Andrew Cagney, Michael Snyder
Cc: Daniel Jacobowitz, Joel Brobecker, gdb-patches
On Aug 5, 10:20pm, Andrew Cagney wrote:
> > 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.
>
> This is true of enums (cf the alpha compiler) but not, I believe, of
> array initializers.
I am unable to find anything in Harbison and Steele which indicates
that a trailing comma is acceptable in an array initializer. (They
don't seem to mention it one way or another.)
I recall using some compilers in the past where a trailing comma in an
array initializer was definitely not accepted. In fact, I was told at
the time that some code I had written which had a trailing comma was
not standards compliant.
Kevin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Question regarding bizarre ','
2002-08-06 16:15 ` Kevin Buettner
@ 2002-08-06 16:44 ` david carlton
0 siblings, 0 replies; 6+ messages in thread
From: david carlton @ 2002-08-06 16:44 UTC (permalink / raw)
To: Kevin Buettner
Cc: Andrew Cagney, Michael Snyder, Daniel Jacobowitz, Joel Brobecker,
gdb-patches, carlton
On Tue, 6 Aug 2002 16:14:58 -0700, Kevin Buettner <kevinb@redhat.com> said:
> I am unable to find anything in Harbison and Steele which indicates
> that a trailing comma is acceptable in an array initializer. (They
> don't seem to mention it one way or another.)
K&R (second edition, of course) section A8.7 says:
The initializer is preceded by =, and is either an expression, or a
list of initializers nested in braces. A list may end with a comma,
a nicety for neat formatting.
It seems to be talking about a general enough context to include
arrays and structs, though it's not _entirely_ clear to me; the second
example on the top of p. 220 is an array with an extra comma at the
end.
David Carlton
carlton@math.stanford.edu
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-08-06 23:44 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-05 18:21 Question regarding bizarre ',' Joel Brobecker
2002-08-05 18:26 ` Daniel Jacobowitz
2002-08-05 18:39 ` Michael Snyder
2002-08-05 19:20 ` Andrew Cagney
2002-08-06 16:15 ` Kevin Buettner
2002-08-06 16:44 ` david carlton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox