|
|
Up |
|
|
  |
Author: aarklonaarklon 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 |
|
  |
Author: Richard HeathfieldRichard Heathfield Date: Feb 16, 2008 09:13
> 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 |
|
  |
Author: vippstarvippstar Date: Feb 16, 2008 09:21
On Feb 16, 7:14 pm, Richard Heathfield wrote:
>> 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 |
|
  |
Author: MartinMartin 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 |
|
  |
Author: Richard HeathfieldRichard Heathfield Date: Feb 16, 2008 09:33
> On Feb 16, 7:14 pm, Richard Heathfield wrote:
>>> 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 |
|
  |
Author: Ben PfaffBen Pfaff Date: Feb 16, 2008 09:38
Richard Heathfield writes:
>> 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 |
|
  |
Author: Richard HeathfieldRichard 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?
|
| |
| no comments |
|
  |
Author: Ben PfaffBen 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 |
|
  |
|
|
  |
|
|
  |
Author: Richard HeathfieldRichard 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 |
|
|
|
|