Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > extra comma

Reply
Thread Tools

extra comma

 
 
SM Ryan
Guest
Posts: n/a
 
      02-17-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
# Hi all,
#
# why does C language permits an extra comma in initializer list

Keypunching.

You don't want to modify an existing card deck just because you
insert a new card in the deck. It's the same reason for the semicolon
rules.

If you want to understand this better, next time to edit a source
file, restrict your actions to only
Deleting an entire line.
Inserting an entire line.
Moving existing lines.
Retyping an entire line.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
OOOOOOOOOO! NAVY SEALS!
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-17-2008
SM Ryan wrote:
> (E-Mail Removed) wrote:
> # Hi all,
> #
> # why does C language permits an extra comma in initializer list
>
> Keypunching.
>
> You don't want to modify an existing card deck just because you
> insert a new card in the deck. It's the same reason for the semicolon
> rules.
>

I thought legalising the trailing comma was new in C99. Not many card
readers where in use in 1999.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
karthikbalaguru
Guest
Posts: n/a
 
      02-17-2008
On Feb 16, 11:23*pm, Richard Heathfield <(E-Mail Removed)> wrote:
> rzed said:
>
> > Richard Heathfield <(E-Mail Removed)> wrote in
> >news:(E-Mail Removed):

>
> >> (E-Mail Removed) said:

>
> <snip>
>
> >>> is there any other purpose than this, if so why ...????

>
> >> No, it's just catering for the lazy.

>
> > And what's wrong with that? A compiler is just catering to those
> > too lazy to code machine language directly.

>
> Right. And keyboards are lame, too - we should be using plugboards.
>
> > One benefit of allowing the extra comma (albeit for the lazy) is
> > that it allows you to manually reorder lists of items in an editor
> > without having to go back and add a comma here and take it away
> > there.

>
> True enough. In fact, that's catering for the good kind of lazy (yes, there
> are at least two kinds). Of course, manually reordering lists is easy
> enough even if you don't like the trailing comma. Reorder, remove last
> comma, recompile, and the editor will tell you where to insert the comma.
>
>
> > I don't see the harm in allowing the trailing comma, and there is
> > at least some productivity benefit.

>
> I certainly wouldn't want to see the feature /removed/ from the language.
> Had I been consulted as to its original addition, I'd probably have argued
> against it, but hey - it's there, it works, it does no particular harm, so
> no big deal. (Of course, removing it from the Standard would do no harm
> either, since the standardisation process is effectively dead in the water
> now.)
>


These extra commas are permitted but are not required.
A benefit is in manual re-oredering.

Karthik Balaguru
 
Reply With Quote
 
Jack Klein
Guest
Posts: n/a
 
      02-17-2008
On Sun, 17 Feb 2008 14:18:51 +1300, Ian Collins <(E-Mail Removed)>
wrote in comp.lang.c:

> SM Ryan wrote:
> > (E-Mail Removed) wrote:
> > # Hi all,
> > #
> > # why does C language permits an extra comma in initializer list
> >
> > Keypunching.
> >
> > You don't want to modify an existing card deck just because you
> > insert a new card in the deck. It's the same reason for the semicolon
> > rules.
> >

> I thought legalising the trailing comma was new in C99. Not many card
> readers where in use in 1999.


Legalizing the trailing comma in an enumeration declaration was new in
C99. The optional trailing comma was left out of the ANSI 89/ISO 90
grammar by mistake.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      02-17-2008
Richard Heathfield wrote:

> (E-Mail Removed) said:
>
>> Hi all,
>>
>> why does C language permits an extra comma in initializer list
>>
>> ex:- int days[] = {
>> 31,28.31,30,31,30,

>
> Between 31 and 28 you meant ,, not ..
>
>> 31,31,30,31,30,31,
>> }
>> i have heard it is for the purpose of automatic code generation

>
> That's supposed to be the reasoning behind such lamenesses, yes. But
> observe:
>
> i = 0;
> printf(" %d", day[i]);
> while(i++ < 12)
> {
> printf(", %d%s", day[i], (i % 6) == 5 ? "\n" : "");
> }
>
> So, as you can see, it isn't actually difficult to generate the code
> without the trailing comma.


int foo[] = {
#ifdef FOO
42, 0,
#endif
37, EOF,
#ifdef BAR
'\n', EXIT_FAILURE,
#endif
#ifdef BAZ
SEEK_END, ERANGE,
#endif
}

--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
Harald van Dijk
Guest
Posts: n/a
 
      02-17-2008
On Sun, 17 Feb 2008 11:15:44 +0000, Army1987 wrote:
> Richard Heathfield wrote:
>> So, as you can see, it isn't actually difficult to generate the code
>> without the trailing comma.

>
> int foo[] = {
> #ifdef FOO
> 42, 0,
> #endif
> 37, EOF,
> #ifdef BAR
> '\n', EXIT_FAILURE,
> #endif
> #ifdef BAZ
> SEEK_END, ERANGE,
> #endif
> }


int foo[] = {
#ifdef FOO
42, 0,
#endif
37, EOF
#ifdef BAR
,'\n', EXIT_FAILURE
#endif
#ifdef BAZ
,SEEK_END, ERANGE
#endif
}

It's not difficult when you have at least one fixed item in the list.
 
Reply With Quote
 
William Pursell
Guest
Posts: n/a
 
      02-17-2008
On Feb 16, 5:38 pm, Ben Pfaff <(E-Mail Removed)> wrote:

> Observe:
>
> int array[] = {
> #ifdef ELEMENT_ONE
> 1,
> #endif

<snip>
> };
>
> versus:
>
> int array[] = {
> #ifdef ELEMENT_ONE
> 1
> # if (defined(ELEMENT_TWO) || defined(ELEMENT_THREE) \
> || defined(ELEMENT_FOUR))
> ,
> # endif
> #endif

<snip>
> };
>
> I know which one I would prefer to maintain.


I can't think of too many cases where it is problematic to do:
int array[] = {
#ifdef ELEMENT_ONE
1,
#endif
SENTINEL
};

to force the existence of at least one fixed
element.


 
Reply With Quote
 
Army1987
Guest
Posts: n/a
 
      02-17-2008
Harald van Dijk wrote:

> int foo[] = {
> #ifdef FOO
> 42, 0,
> #endif
> 37, EOF
> #ifdef BAR
> ,'\n', EXIT_FAILURE
> #endif
> #ifdef BAZ
> ,SEEK_END, ERANGE
> #endif
> }
>
> It's not difficult when you have at least one fixed item in the list.

But it is so ugly!


--
Army1987 (Replace "NOSPAM" with "email")
 
Reply With Quote
 
aarklon@gmail.com
Guest
Posts: n/a
 
      02-17-2008
On Feb 16, 10:33 pm, Richard Heathfield <(E-Mail Removed)> wrote:
> (E-Mail Removed) said:
>
> > On Feb 16, 7:14 pm, Richard Heathfield <(E-Mail Removed)> wrote:
> >> (E-Mail Removed) said:

>
> >> > Hi all,

>
> >> > why does C language permits an extra comma in initializer list

>
> >> > ex:- int days[] = {
> >> > 31,28.31,30,31,30,

>
> >> Between 31 and 28 you meant ,, not ..

> > How do you know?

>
> Call me psychic if you like.
>
> > 28.31 is a valid value for initializing in integer
> > context.

>
> Yes, but on this occasion it was not what was intended.


Yeah richard is correct he is indeed psychic to a certain extent
I did n't mean 28.31 , i meant 28,31
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does return-by-value mean extra copies and extra overhead? mathieu C++ 3 09-04-2009 04:25 PM
Extra Comma in enum is Valid? Sriram Rajagopalan C Programming 5 08-09-2005 09:34 AM
How to format $mail_from with 2 variables separated by a comma? Jason Miles Perl 1 05-28-2004 02:48 AM
server.mappath with comma in foldername? Martin Pahlplatz ASP .Net 0 11-11-2003 10:08 PM
add a comma Ryan Moore ASP .Net 4 08-28-2003 03:32 PM



Advertisments