2疑惑! [英] 2 doubts !

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

问题描述

大家好,


i有两个疑问。


1.这个总是被定义吗?


int i = 10;

int a = i ++ + i ++;

而且,我在gcc中试过这个,答案是20,所以序列点是什么

用于评估像i ++ + i ++这样的东西???


2.a [i] = i ++;没有在语言中定义........这是因为,i ++

返回一个临时的,在这样的特定语句中,它不是

可能的实际上是在做完i ++之后提到我???

感谢你,

ranjan。

解决方案
>各位大家好,

还有一个你好回来。

我有2个疑惑。
如果你只有两个,那么你已经获得了启发。

1.这个总是被定义吗?
实际上它总是被定义,从实现到实现的方式不同。

int i = 10;
int a = i ++ + i ++;
而且,我在gcc中试过这个,答案是20,>那么序列点是什么来评估像i ++ + i ++这样的东西?
声明末尾的分号。声明中没有序列

积分。


答案甚至可能是21。


请勿以这种方式编写实际程序。调试工作可能会对我或其他一些忙碌的人造成损失。 ;-)

2.a [i] = i ++;语言中没有定义........这是因为,i ++
返回一个临时的,在这样的特定语句中,它不可能在做完i ++后实际引用i吗? ??


可能吗?绝对。有意义还是推荐?绝对没有。

''=''也没有序列点。因此,结果

可能会在最初的i位置或i + 1处结束。对于编译器来说,这是一个

守场员的选择。有些人可能会警告你这个

构造,其他人不会。

感谢你,
ranjan。


$ b $你很受欢迎。安全的旅程和快乐的编程。


maadhuu写道:

我有2个疑问。

1.这总是被定义吗?

int i = 10;
int a = i ++ + i ++;
而且,我在gcc中试过这个,答案是20,所以什么序列指出评估像i ++ + i ++这样的东西???

2.a [i] = i ++;语言中没有定义........这是因为,i ++
返回一个临时的,在这样的特定语句中,它不可能在做完i ++后实际引用i吗? ??




在不包含序列点的表达式中,对象可能不会在不同的子表达式中修改和访问
(因为

子表达式的效果可以按任何顺序发生。)

八月


" maadhuu" <毫安************ @ yahoo.com>写道:

大家好,

我有两个疑问。

1。这是永远定义的吗?

int i = 10;
int a = i ++ + i ++;
而且,我在gcc中试过这个,答案是20,所以是什么序列点
评估像i ++ + i ++这样的东西???


未定义的行为,我被修改两次没有干预序列

点。见常见问题第3.2节。

2.a [i] = i ++;语言中没有定义........这是因为,i ++
返回一个临时的,在这样的特定语句中,它不可能在做完i ++后实际引用i吗? ??




未定义的行为,我在不干预

序列点的情况下进行评估和修改。请参阅常见问题解答第3.1节。


最好的问候

-

Irrwahn Grausewitz(ir ******* @ freenet .de)

欢迎来到clc: http ://www.ungerhu.com/jxh/clc.welcome.txt

clc faq-list: http://www.faqs.org/faqs/C-faq/faq/

clc频繁答案: http://benpfaff.org/writings/clc


hello everybody,

i have 2 doubts .

1. is this always defined ??

int i =10;
int a = i++ + i++;
and also, i tried this in gcc, answer was 20, so what the sequence points
for evaluation of something like i++ + i++ ???

2.a[i] = i++; is not defined in the language........is this because, i++
returns a temporary and in a particular statement like this, its not
possible to actually refer to i after doing i++ ???
thanking you,
ranjan.

解决方案

> hello everybody,
And a howdy right back.

i have 2 doubts . If you''re down to only two, you have achieved enlightment.
1. is this always defined ?? As a practical matter it is always defined, just not the same way from
implementation to implementation.
int i =10;
int a = i++ + i++;
and also, i tried this in gcc, answer was 20, > so what the sequence points
for evaluation of something like i++ + i++ ??? The semicolon at the end of the statement. There are no sequence
points within the statement.

It is even possible for the answer to be 21.

Please never write actual programs this way. The debugging job might
fall on me or some other busy person. ;-)
2.a[i] = i++; is not defined in the language........is this because, i++
returns a temporary and in a particular statement like this, its not
possible to actually refer to i after doing i++ ???
Possible? absolutely. Meaningful or recommended? absolutely NOT.
There is no sequence point across ''='' either. Therefore the result
could end up at either the original ''i'' location or at ''i+1''. It''s a
fielder''s choice for the compiler. Some may warn you about this
construct, others won''t.
thanking you,
ranjan.


You''re welcome. Safe journey and much happy programming.


maadhuu wrote:

i have 2 doubts .

1. is this always defined ??

int i =10;
int a = i++ + i++;
and also, i tried this in gcc, answer was 20, so what the sequence points
for evaluation of something like i++ + i++ ???

2.a[i] = i++; is not defined in the language........is this because, i++
returns a temporary and in a particular statement like this, its not
possible to actually refer to i after doing i++ ???



In an expression that contains no sequence points an object may not be
modified and accessed in different subexpressions (since the side
effects of the subexpressions may take place in any order).
August


"maadhuu" <ma************@yahoo.com> wrote:

hello everybody,

i have 2 doubts .

1. is this always defined ??

int i =10;
int a = i++ + i++;
and also, i tried this in gcc, answer was 20, so what the sequence points
for evaluation of something like i++ + i++ ???
Undefined behaviour, i is modified twice without intervening sequence
point. See FAQ section 3.2.
2.a[i] = i++; is not defined in the language........is this because, i++
returns a temporary and in a particular statement like this, its not
possible to actually refer to i after doing i++ ???



Undefined behaviour, i is evaluated and modified without intervening
sequence point. See FAQ section 3.1.

Best regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
clc frequent answers: http://benpfaff.org/writings/clc


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

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