逗号的序列点? [英] Sequence point at comma?

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

问题描述



我知道逗号上有一个序列点,例如:


int main(无效)

{

int a = 1;

a ++,++ a,a * = 3,a<< = 4; / *完全没问题* /

}

但这还包括用于分隔函数参数的逗号吗?

以下代码是否已损坏?


void Func(int,int,int,int);


int main(void)

{

int a = 1;


Func(a ++,++ a,a * = 3,a<<< =< =<<<<>;

}

-


Frederick Gotham


I know there''s a sequence point at a comma, e.g.:

int main(void)
{
int a = 1;
a++, ++a, a *= 3, a <<= 4; /* Perfectly okay */
}
But does that also include the commas which separate function arguments? Is
the following code broken?

void Func( int, int, int, int );

int main(void)
{
int a = 1;

Func( a++, ++a, a *= 3, a <<= 4 );
}
--

Frederick Gotham

推荐答案

Frederick Gotham schrieb:
Frederick Gotham schrieb:
我知道逗号中有一个序列点,例如:

int main(void)
{a / 1;

a ++,++ a,a * = 3,a<< = 4; / *完全没问题* /
}

但这还包括用于分隔函数参数的逗号吗?


No.

以下代码是否已损坏?

void Func(int,int,int,int );

int main(void)
{a / 1;

Func(a ++,++ a,a * = 3, a<< = 4);
}
I know there''s a sequence point at a comma, e.g.:

int main(void)
{
int a = 1;
a++, ++a, a *= 3, a <<= 4; /* Perfectly okay */
}
But does that also include the commas which separate function arguments?
No.
Is
the following code broken?

void Func( int, int, int, int );

int main(void)
{
int a = 1;

Func( a++, ++a, a *= 3, a <<= 4 );
}




是的。

干杯

迈克尔

-

电子邮件:我的是/ at / gmx / dot / de地址。



Yes.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


2006年6月28日星期三,格林尼治标准时间16:12:36,Frederick Gotham

< fg ******* @ SPAM.com>写道:
On Wed, 28 Jun 2006 16:12:36 GMT, Frederick Gotham
<fg*******@SPAM.com> wrote:

我知道逗号上有一个序列点,例如:

int main(void)
{
int a = 1;

a ++,++ a,a * = 3,a<< = 4; / *完全没问题* /
}

但这还包括用于分隔函数参数的逗号吗?以下代码是否已损坏?

void Func(int,int,int,int);

int main(void)
{
int a = 1;

Func(a ++,++ a,a * = 3,a<< = 4);
}

I know there''s a sequence point at a comma, e.g.:

int main(void)
{
int a = 1;
a++, ++a, a *= 3, a <<= 4; /* Perfectly okay */
}
But does that also include the commas which separate function arguments? Is
the following code broken?

void Func( int, int, int, int );

int main(void)
{
int a = 1;

Func( a++, ++a, a *= 3, a <<= 4 );
}




是的,它坏了:


ISO / IEC 9899:1999


6.5.2.2函数调用< br $>
约束

....

10函数指示符的评估顺序,实际的

参数,实际参数中的子表达式是

未指定,但在实际调用之前有一个序列点。



Yes, it is broken:

ISO/IEC 9899:1999

6.5.2.2 Function calls
Constraints
....
10 The order of evaluation of the function designator, the actual
arguments, and subexpressions within the actual arguments is
unspecified, but there is a sequence point before the actual call.


Frederick Gotham写道:
Frederick Gotham wrote:
我知道逗号上有一个序列点,例如:

int main(void)
{
int a = 1;

a ++,++ a,a * = 3,a<< = 4; / *完全没问题* /
}


是的。不仅每个操作之间都有一个序列点,而且

的评估顺序保证是从左到右,结果

将具有类型和valud最右边的表达式。

但是这还包括分隔函数参数的逗号吗?


不,逗号分隔函数参数或列表项不是

逗号运算符,也不引入序列点。

以下代码是否已损坏?


是。

void Func(int,int,int,int);

int main(void)
{
int a = 1;

Func(a ++,++ a,a * = 3,a<< = 4);
}
I know there''s a sequence point at a comma, e.g.:

int main(void)
{
int a = 1;
a++, ++a, a *= 3, a <<= 4; /* Perfectly okay */
}
Yes. Not only is there a sequence point between each operation but the
order of evaluation is guaranteed to be from left to right, the result
of which will have the type and valud of the rightmost expression.
But does that also include the commas which separate function arguments?
No, commas seperating function arguments or list items are not the
comma operator and do not introduce a sequence point.
Is the following code broken?
Yes.
void Func( int, int, int, int );

int main(void)
{
int a = 1;

Func( a++, ++a, a *= 3, a <<= 4 );
}




函数参数可以按任何顺序进行评估,因为

在a的修改之间没有序列点。行为是

undefined。


Robert Gamble



The function arguments may be evaluated in any order and since there is
no sequence point between the modifications of "a" the behavior is
undefined.

Robert Gamble


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

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