j***i 发帖数: 1278 | 1 C-faq said is compile error. it is undefined.
seems new standard it is right,
I test in gcc, it works?
Is that ture |
X****r 发帖数: 3557 | 2 Undefined behavior. It is not ill-formed (i.e. "compile error"),
so the code compiles and runs, just that it can lead to any result,
including, but not limited to, the one you are expecting.
【在 j***i 的大作中提到】![](/moin_static193/solenoid/img/up.png) : C-faq said is compile error. it is undefined. : seems new standard it is right, : I test in gcc, it works? : Is that ture
|
t****t 发帖数: 6806 | 3 it's either compile error or undefined. can not be both. in this case it's
undefined.
which new standard said it is right?
【在 j***i 的大作中提到】![](/moin_static193/solenoid/img/up.png) : C-faq said is compile error. it is undefined. : seems new standard it is right, : I test in gcc, it works? : Is that ture
|
G****A 发帖数: 4160 | 4 红猪能不能解释一下,为什么这种表述有问题。
【在 X****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Undefined behavior. It is not ill-formed (i.e. "compile error"), : so the code compiles and runs, just that it can lead to any result, : including, but not limited to, the one you are expecting.
|
X****r 发帖数: 3557 | 5 因为没有规定i++的副作用,就是把i增加1,是在a[i]取(左)值之前
还是之后。
【在 G****A 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 红猪能不能解释一下,为什么这种表述有问题。
|
G****A 发帖数: 4160 | 6 但是我在G++下测试了一下,好像都是当作先扶植再++来处理,没有任何报错。
【在 X****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 因为没有规定i++的副作用,就是把i增加1,是在a[i]取(左)值之前 : 还是之后。
|
S*********g 发帖数: 5298 | 7 undefined =/= 报错
【在 G****A 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 但是我在G++下测试了一下,好像都是当作先扶植再++来处理,没有任何报错。
|
d****p 发帖数: 685 | 8 C++不规定计算子表达式的次序(除了&& || :?是例外).
以这个例子来说,=左右是两个子表达式,所以可以先左后右或是反过来.
这个和操作符的优先次序是两回事.操作符优先次序适用于同一个操作数能被两个操作
符作用时,取那一个避免歧义.C++没
有特定次序运算子表达式,是为了支持优化,代价是希望编码员不要写出上述导致歧义的
代码.
虽然标准没有规定次序,但具体的编译器肯定有内部次序(既然标准没规定).我胡乱猜测
a[i]优先可能的原因(1)lvalue优先,因
为优化多针对rvalue(2)[]的优先级高于postfix ++?
【在 G****A 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 但是我在G++下测试了一下,好像都是当作先扶植再++来处理,没有任何报错。
|
M******r 发帖数: 469 | 9 undefined behavior
【在 j***i 的大作中提到】![](/moin_static193/solenoid/img/up.png) : C-faq said is compile error. it is undefined. : seems new standard it is right, : I test in gcc, it works? : Is that ture
|
G****A 发帖数: 4160 | 10 thanks.
一语惊醒梦中人阿~
【在 d****p 的大作中提到】![](/moin_static193/solenoid/img/up.png) : C++不规定计算子表达式的次序(除了&& || :?是例外). : 以这个例子来说,=左右是两个子表达式,所以可以先左后右或是反过来. : 这个和操作符的优先次序是两回事.操作符优先次序适用于同一个操作数能被两个操作 : 符作用时,取那一个避免歧义.C++没 : 有特定次序运算子表达式,是为了支持优化,代价是希望编码员不要写出上述导致歧义的 : 代码. : 虽然标准没有规定次序,但具体的编译器肯定有内部次序(既然标准没规定).我胡乱猜测 : a[i]优先可能的原因(1)lvalue优先,因 : 为优化多针对rvalue(2)[]的优先级高于postfix ++?
|
|
|
e*u 发帖数: 99 | 11 ';' defines sequence point, but '=' does NOT.
All the side effect is done/cleared after the sequence point.
But the order is NOT guaranteed between this sequence point and
previous one. In this case, 'i' in a[i] is NOT guaranteed
to be updated OR not because '=' is NOT a sequence point.
【在 G****A 的大作中提到】![](/moin_static193/solenoid/img/up.png) : thanks. : 一语惊醒梦中人阿~
|
g******r 发帖数: 213 | 12 是,不是; ;已经是行末尾了还sequence不sequence.
【在 e*u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : ';' defines sequence point, but '=' does NOT. : All the side effect is done/cleared after the sequence point. : But the order is NOT guaranteed between this sequence point and : previous one. In this case, 'i' in a[i] is NOT guaranteed : to be updated OR not because '=' is NOT a sequence point.
|
d****p 发帖数: 685 | 13 There will be a sequence point in following cases:
1. End of full expression
2. End of function call
3. start/end of member/base in class initializer list
4. any subexpression in || && or :?.
【在 g******r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 是,不是; ;已经是行末尾了还sequence不sequence.
|
g******r 发帖数: 213 | 14 from ANSI C standard:
you write X, Y to first evaluate X as a side-effects context expression and
then to evaluate Y. There is a sequence point between the evaluation of the
two operands.
我的意思是;没争议,总不可能执行完后面一句再执行前面一句吧。我觉得那人想强调
的是,这个运算符。这个运算符也是有sequence point的。
【在 d****p 的大作中提到】![](/moin_static193/solenoid/img/up.png) : There will be a sequence point in following cases: : 1. End of full expression : 2. End of function call : 3. start/end of member/base in class initializer list : 4. any subexpression in || && or :?.
|
d****p 发帖数: 685 | 15 Sure :-) I didn't read your post carefully.
and
the
【在 g******r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : from ANSI C standard: : you write X, Y to first evaluate X as a side-effects context expression and : then to evaluate Y. There is a sequence point between the evaluation of the : two operands. : 我的意思是;没争议,总不可能执行完后面一句再执行前面一句吧。我觉得那人想强调 : 的是,这个运算符。这个运算符也是有sequence point的。
|