Topic: trailing comma in enumerator-list


Author: bgb@pspd51.ATT.COM (nq4120c00-Beuning)
Date: 1995/07/18
Raw View
Hi,

A number of people around here write code like this:
 enum E {
  a,
  b,
 };

with a comma after the last enum member.  Cfront has always
accepted this without complaint.

I looked in both the ARM and the draft ANSI C++ standard and
neither one allows the trailing comma.  Did this lose out
along the way somewhere?

The reason we put the trailing comma in the code is to avoid
a nasty problem with our source code control system (based on
SCCS).

Another way to avoid the SCCS problem would be to code like this:
 enum E {
    a
  , b
  , c
 };

but thats a little ugly.

The SUN Pro compiler gives us an 'anachronism' message for the
trailing comma.  I don't see this anachronism listed in the draft
standard.

  Thanks,
  Brian Beuning
  b.beuning@att.com





Author: jsa@edg.com (J. Stephen Adamczyk)
Date: 1995/07/18
Raw View
In article <BGB.95Jul18120456@pspd51.ATT.COM> bgb@pspd51.ATT.COM (nq4120c00-Beuning) writes:
>A number of people around here write code like this:
> enum E {
>  a,
>  b,
> };
>
>with a comma after the last enum member.  Cfront has always
>accepted this without complaint.
>
>I looked in both the ARM and the draft ANSI C++ standard and
>neither one allows the trailing comma.  Did this lose out
>along the way somewhere?

If you look in the ISO/ANSI C standard, you'll find that it too
disallows a comma in that position, which is why the ARM and the
draft C++ standard do also.  cfront was just permissive in this
regard.

Your SCCS argument has some merit, but probably not enough merit
to justify an incompatibility with C in this regard.  IMHO.

Steve Adamczyk
Edison Design Group








Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/07/19
Raw View
bgb@pspd51.ATT.COM (nq4120c00-Beuning) writes:


>The SUN Pro compiler gives us an 'anachronism' message for the
>trailing comma.  I don't see this anachronism listed in the draft
>standard.

The Sun "anachronism" messages refer to code which was accepted
by the previous cfront-based compiler, but which isn't valid
(and which probably was never valid even if accepted previously)
and which will not be accepted by future Sun compilers.
--
Steve Clamage, stephen.clamage@eng.sun.com





Author: larsenms@cig.mot.com (Mark S. Larsen)
Date: 1995/07/19
Raw View
In article <DBxrnC.8y0@edg.com> jsa@edg.com (J. Stephen Adamczyk) writes:

   Newsgroups: comp.std.c++
   Path: newdelph.cig.mot.com!mothost!lego.wes.mot.com!mdisea!mmddvan!vanbc.wimsey.com!news.mindlink.net!sol.ctr.columbia.edu!howland.reston.ans.net!newsfeed.internetmci.com!uunet!in1.uu.net!edg1!jsa
   From: jsa@edg.com (J. Stephen Adamczyk)
   Organization: Edison Design Group Inc.
   References: <BGB.95Jul18120456@pspd51.ATT.COM>
   Distribution: comp
   Date: Tue, 18 Jul 1995 23:52:23 GMT
   Lines: 27

   In article <BGB.95Jul18120456@pspd51.ATT.COM> bgb@pspd51.ATT.COM (nq4120c00-Beuning) writes:
   >A number of people around here write code like this:
   > enum E {
   >  a,
   >  b,
   > };
   >
   >with a comma after the last enum member.  Cfront has always
   >accepted this without complaint.
   >
   >I looked in both the ARM and the draft ANSI C++ standard and
   >neither one allows the trailing comma.  Did this lose out
   >along the way somewhere?

   If you look in the ISO/ANSI C standard, you'll find that it too
   disallows a comma in that position, which is why the ARM and the
   draft C++ standard do also.  cfront was just permissive in this
   regard.

   Your SCCS argument has some merit, but probably not enough merit
   to justify an incompatibility with C in this regard.  IMHO.

   Steve Adamczyk
   Edison Design Group

I agree that to add one new enum value one should not have to change one line.
and add one line. The method I prefer is to have a sentinal value at the end of
the list:

enum E {
 a,
 b,

 /* leave this at the end */
 E_MAX
};

Then when I need to add enum value "c", I change it to:

enum E {
 a,
 b,
 c,

 /* leave this at the end */
 E_MAX
};

I have added only one line. Also I have a value I can use for situations like.

int array_indexed_by_enum[E_MAX];

for (index = 0; index < E_MAX; index++)
{
.
.
.
}

--
-- Mark Larsen                         | Motorola - IL27
-- Desk/Voice: (708)632-4704           | 3205 North Wilke
-- FAX:        (708)632-3741           | Arlington Heights, IL 60004
-- E-Mail:     larsenms@cig.mot.com    | USA (Country Code 001)





Author: andrewfg@dai.ed.ac.uk (Andrew Fitzgibbon)
Date: 1995/07/20
Raw View
J. Stephen Adamczyk (jsa@edg.com) wrote:
< In article <BGB.95Jul18120456@pspd51.ATT.COM> bgb@pspd51.ATT.COM writes:
< > [trailing comma is useful with SCCS]
< [the ISO/ANSI C standard disallows a comma in that position]

< Your SCCS argument has some merit, but probably not enough merit
< to justify an incompatibility with C in this regard.  IMHO.

That's true, I often compile my C++ code with a C compiler just to check
that it doesn't use any extensions that are not in the C standard :-)

A.

--
Andrew Fitzgibbon (Research Associate),                     andrewfg@ed.ac.uk
Artificial Intelligence, Edinburgh University.               +44 031 650 4504
<a href=http://www.dai.ed.ac.uk/staff/personal_pages/andrewfg> Home Page </a>
                         "Never say there is no way" -- me.