是i = i ++;坏风格? [英] Is i = i++; bad style?

查看:59
本文介绍了是i = i ++;坏风格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i = i ++;


gcc在这行代码上发出警告,说警告:

操作'我''可能是未定义的。


但我认为,在声明执行结束时,

变量i最终会增加一,我是对吧?

i = i++;

The gcc gives out a warning on this line of code, saying "warning:
operation on `i'' may be undefined".

But I think, at the end of the execution of the statement, the
variable i is eventually increased by one, am I right?

推荐答案

7月6日上午11点25分,lovecreatesbea ... @ gmail.com

< lovecreatesbea ... @ gmail.comwrote:
On Jul 6, 11:25 am, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.comwrote:

i = i ++;


gcc给出在这行代码上发出警告,说警告:

对'我''的操作可能是未定义的。


但我认为,在在声明执行结束时,

变量我最终增加了一个,对不对?
i = i++;

The gcc gives out a warning on this line of code, saying "warning:
operation on `i'' may be undefined".

But I think, at the end of the execution of the statement, the
variable i is eventually increased by one, am I right?



作为复合表达式的一部分,i = i ++(一个表达式,没有

semocolon紧随其后)可能是未定义的值,对吧?

As a part of a compound expression, i = i++ (an expression, no
semocolon followed) may be undefined value, right?


7月5日晚上11点28分,lovecreatesbea ... @ gmail.com

< lovecreatesbea ... @ gmail.comwrote:
On Jul 5, 11:28 pm, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.comwrote:

7月6日上午11点25分,lovecreatesbea ... @ gmail.com


< lovecreatesbea ... @ gmail.comwrote:
On Jul 6, 11:25 am, "lovecreatesbea...@gmail.com"

<lovecreatesbea...@gmail.comwrote:

i = i ++;
i = i++;


gcc在这行代码上发出警告,说'警告:

操作'i' '可能未定义'。
The gcc gives out a warning on this line of code, saying "warning:
operation on `i'' may be undefined".


但我认为,在执行声明结束时,

变量i最终会增加一个, 我对吗?
But I think, at the end of the execution of the statement, the
variable i is eventually increased by one, am I right?



作为复合表达式的一部分,i = i ++(一个表达式,没有

semocolon紧随其后)可能是未定义的值,对吧?


As a part of a compound expression, i = i++ (an expression, no
semocolon followed) may be undefined value, right?



它既未被定义为较大表达式的一部分,也未被定义为

独立表达式。 9899:1999§6.5p2读取:


在上一个和下一个序列点之间,一个物体应该有它的

储值
$ b通过表达式的评估,$ b最多修改一次。此外,

之前的值

只能读取以确定要存储的值。


作业不具备引入一个序列点,所以我被修改了两次

没有插入序列点,一次由++运算符和

一次被赋值。违反应的在
约束之外(如这里的情况)会导致未定义的行为。另请参阅

< http://www.c-faq.com/question 3.3。


Robert Gamble

It is undefined both as part of a larger expression and as a
standalone expression. 9899:1999 §6.5p2 reads:

"Between the previous and next sequence point an object shall have its
stored value
modified at most once by the evaluation of an expression. Furthermore,
the prior value
shall be read only to determine the value to be stored."

Assignment does not introduce a sequence point so i is modified twice
without an intervening sequence point, once by the ++ operator and
once by the assignment. Violation of a "shall" outside of a
constraint (as is the case here) causes undefined behavior. See also
<http://www.c-faq.com/question 3.3.

Robert Gamble


7月6日凌晨4:25,lovecreatesbea ... @ gmail.com

< lovecreatesbea ... @ gmail.comwrote:
On Jul 6, 4:25 am, "lovecreatesbea...@gmail.com"
<lovecreatesbea...@gmail.comwrote:

i = i ++;


gcc在这行代码上发出警告,说警告:

对'i''的操作可能是未定义的。


但我认为,在执行声明结束时,

变量我最终会增加一个,对吗?
i = i++;

The gcc gives out a warning on this line of code, saying "warning:
operation on `i'' may be undefined".

But I think, at the end of the execution of the statement, the
variable i is eventually increased by one, am I right?



原帖如何!没有人曾经想过要问i = i ++

之前是否有意义。没有必要搜索谷歌或C常见问题解答来找出

- 这是C编程人类的新领域。

What an original post! No one''s ever thought to ask whether i=i++
makes sense before. No point searching Google or the C FAQ to find out
- this is new territory for C-programming humanity.


这篇关于是i = i ++;坏风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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