额外的逗号 [英] extra comma

查看:73
本文介绍了额外的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


为什么C语言在初始化列表中允许额外的逗号


ex: - int days [] = {

31,28.31,30,31,30,

31,31,30,31,30,31,

}

i听说它是为了自动代码生成的目的

还有除此之外的其他目的,如果是这样的原因...... ????

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 ...????

推荐答案

aa*****@gmail.com 说:

大家好,


为什么C语言在初始化列表中允许额外的逗号


ex: - int days [] = {

31,28.31,30,31,30,
Hi all,

why does C language permits an extra comma in initializer list

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



31到28之间你意思是,不是..

Between 31 and 28 you meant ,, not ..


31,31,30,31,30,31,

}

i听说它是为了自动代码生成的目的
31,31,30,31,30,31,
}
i have heard it is for the purpose of automatic code generation



那应该是这种跛脚背后的原因,是的。但

观察:


i = 0;

printf("%d",day [i]);

while(i ++< 12)

{

printf(",%d%s",day [i],(i%6) )== 5?" \ n":"");

}


所以,正如你所看到的,它不是''实际上很难生成代码

没有尾随逗号。

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.


还有其他目的,如果是这样,为什么...... ????
is there any other purpose than this, if so why ...????



不,它只是为懒人提供服务。


-

Richard Heathfield< http://www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

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

--
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


2月16日晚上7点14分,Richard Heathfield< r ... @ see.sig.invalidwrote:
On Feb 16, 7:14 pm, Richard Heathfield <r...@see.sig.invalidwrote:

aark ... @ gmail.com说:
aark...@gmail.com said:

大家好,
Hi all,


为什么C语言在初始化列表中允许额外的逗号
why does C language permits an extra comma in initializer list


ex: - int days [] = {

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



在31到28之间你的意思是,不是..


Between 31 and 28 you meant ,, not ..



你怎么知道的? 28.31是在整数

上下文中初始化的有效值。

How do you know? 28.31 is a valid value for initializing in integer
context.


>
>

31,31,30,31,30,31,

}

i听说是为了自动代码生成的目的
31,31,30,31,30,31,
}
i have heard it is for the purpose of automatic code generation



这应该是这种跛脚背后的原因,是的。但

观察:


i = 0;

printf("%d",day [i]);

while(i ++< 12)

{

printf(",%d%s",day [i],(i%6) )== 5?" \ n":"");


}


所以,正如你所看到的,在没有尾随逗号的情况下生成代码

实际上并不困难。


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.



模数甚至条件检查在某些地方可能很贵我想b $ b猜测。

注意它是'不仅允许在初始化列表中使用但在任何地方

使用{elements}。 (我不知道它的正确用语)

例如,printf("%zu \ n",sizeof(char []){1,2,3,}) ;

Modulus or even the conditional check could be expensive somewhere I
guess.
Notice it''s not only allowed in an "initializer list" but anywhere
where {elements} is used. (I don''t know the proper term for it)
For example, printf("%zu\n", sizeof (char[]){1,2,3,});


2月16日,4:55 * pm,aark ... @ gmail.com写道:
On Feb 16, 4:55*pm, aark...@gmail.com wrote:

为什么C语言在初始化列表中允许额外的逗号

...

*我听说它是​​为了自动代码生成的目的

还有除此之外的任何其他目的,如果是这样,为什么...... ????
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 ...????



根据K& R2(第196页),这是整洁格式的精确。


-

马丁

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

--
Martin


这篇关于额外的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆