extra comma
  Home FAQ Contact Sign in
comp.lang.c only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c Profile…
 Up
extra comma         


Author: aarklon
Date: Feb 16, 2008 08:55

Hi all,

why does C language permits an extra comma in initializer list

ex:- int days[] = {
31,28.31,30,31,30,
31,31,30,31,30,31,
}
i have heard it is for the purpose of automatic code generation
is there any other purpose than this, if so why ...????
28 Comments
Re: extra comma         


Author: Richard Heathfield
Date: Feb 16, 2008 09:13

aarklon@gmail.com 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" : "");
}
Show full article (0.94Kb)
no comments
Re: extra comma         


Author: vippstar
Date: Feb 16, 2008 09:21

On Feb 16, 7:14 pm, Richard Heathfield wrote:
> aark...@gmail.com 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? 28.31 is a valid value for initializing in integer
context.
Show full article (1.11Kb)
no comments
Re: extra comma         


Author: Martin
Date: Feb 16, 2008 09:26

On Feb 16, 4:55 pm, aark...@gmail.com wrote:
> why does C language permits an extra comma in initializer list
> ...
>  i have heard it is for the purpose of automatic code generation
> is there any other purpose than this, if so why ...????

According to K&R2 (p196) it is "a nicety for neat formatting."

--
Martin
no comments
Re: extra comma         


Author: Richard Heathfield
Date: Feb 16, 2008 09:33

vippstar@gmail.com said:
> On Feb 16, 7:14 pm, Richard Heathfield wrote:
>> aark...@gmail.com 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.

Show full article (1.00Kb)
no comments
Re: extra comma         


Author: Ben Pfaff
Date: Feb 16, 2008 09:38

Richard Heathfield writes:
> aarklon@gmail.com said:
>> why does C language permits an extra comma in initializer list
>> 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" : "");
> }

Observe:
Show full article (1.33Kb)
no comments
Re: extra comma         


Author: Richard Heathfield
Date: Feb 16, 2008 10:01

Ben Pfaff said:
> Richard Heathfield writes:


> I know which one I would prefer to maintain.

Surely the whole point of generating the code automatically is that you
don't have to maintain it?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
no comments
Re: extra comma         


Author: Ben Pfaff
Date: Feb 16, 2008 10:01

Richard Heathfield writes:
> Ben Pfaff said:
>
>> Richard Heathfield writes:
>
>
>
>> I know which one I would prefer to maintain.
>
> Surely the whole point of generating the code automatically is that you
> don't have to maintain it?

The code that you snipped was not an example of automatically
generated code.
--
"Welcome to the wonderful world of undefined behavior, where the demons
are nasal and the DeathStation users are nervous." --Daniel Fox
no comments
Re: extra comma         


Author: rzed
Date: Feb 16, 2008 10:03

Richard Heathfield wrote in
news:f9CdnWNCHtOThCranZ2dnUVZ8j6dnZ2d@bt.com:
Show full article (1.35Kb)
no comments
Re: extra comma         


Author: Richard Heathfield
Date: Feb 16, 2008 10:17

Ben Pfaff said:
> Richard Heathfield writes:
>
>> Ben Pfaff said:
>>
>>> Richard Heathfield writes:
>>
>>
>>
>>> I know which one I would prefer to maintain.
>>
>> Surely the whole point of generating the code automatically is that you
>> don't have to maintain it?
>
> The code that you snipped was not an example of automatically
> generated code.

Oh. I see.



Well then - perhaps you ought to automate it! :-)
Show full article (0.71Kb)
no comments
1 2 3