a [i] = x [a [i]] ++ [英] a[i] = x[a[i]]++

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

问题描述

有没有人知道这项任务是否:


a [i] = x [a [i]] ++;


是在C中是合法的,如果是这样,x []中的数组元素是后递增的?


即,[i]的旧值或新值是否确定了索引中的索引

x []后增加数组元素。


我怀疑结果是未定义的 - 但我是对的吗?


Brian Gladman

Does anyone here know whether the assignment:

a[i] = x[ a[i] ]++;

is legal in C and, if so, what array element in x[] is post incremented?

That is, does the old or the new value of a[i] determine the index in
x[] of the post incremented array element.

I rather suspect the result is undefined - but am I right?

Brian Gladman

推荐答案

BRG写道:
BRG wrote:
这里有没有人知道作业是否:

a [i] = x [a [i]] ++;

是合法的C


我想这个代码可以简化为


i = x [i] ++;


而不失一般性。


问题归结为检查i的旧值是否被读取为
仅用于确定我的新值。这个要求似乎是以非常非正式的方式在标准中制定的(我有疑问

关于仅的确切含义),但意图是,如果我确实记得正确,要求

表达式内的信息流强制读取旧值_before_新值是

存储。有一个缺陷报告处理类似的问题

是否


a [a [i]] = 5;


产生未定义的行为。 (不幸的是,我不记得缺陷

数。)


乍一看,在这个表达式中满足了这个要求,即

这个表达式没问题。


然而,在第二眼看来,人们可以争辩说这个表达式

违反了只有这个表达式。要求:在这种情况下,''i'的旧值是

读取不仅要确定它的新值,还要确定哪个'/ b $ b元素'' x []''递增。就个人而言,我不认为这是一个有效的

论证(考虑到我认为的意图),但我可能是错的。

,如果是这样的话, x []中的哪个数组元素后递增?


由'a [i]''的旧值指定的那个。

即,a的旧值或新值是否为[ i]确定后递增数组元素的
x []中的索引。


应该是旧的。

我怀疑结果是不确定的 - 但我是对的吗?
Does anyone here know whether the assignment:

a[i] = x[ a[i] ]++;

is legal in C
I think this code can be simplified to

i = x[i]++;

without loss of generality.

The question boils down to checking whether the old value of ''i'' is read
only to determine the new value of ''i''. This requirement appears to be
formulated in the standard in rather informal fashion (I have my doubts
about the exact meaning of that "only"), but the intent was, if I
remember correctly, to require the flow of information inside the
expression to force the old value to be read _before_ the new value is
stored. There''s a defect report that deals with a similar issue of
whether the

a[a[i]] = 5;

produces undefined behavior. (Unfortunately, I don''t remember the defect
number.)

On the first sight, in this expression this requirement is met, i.e.
this expression is OK.

However, on the second sight, one can argue that this expression
violates that "only" requirement: in this case the old value of ''i'' is
read not only to determine its new value, but also to determine, which
element of ''x[]'' to increment. Personally, I don''t think this is a valid
argument (considering what I think was the intent), but I could be wrong.
and, if so, what array element in x[] is post incremented?
The one specified by the old value of ''a[i]''.
That is, does the old or the new value of a[i] determine the index in
x[] of the post incremented array element.
Should be the old one.
I rather suspect the result is undefined - but am I right?



我会说我宁愿怀疑结果已定义。


-

祝你好运,

Andrey Tarasevich



I''d say that I rather suspect that the result is defined.

--
Best regards,
Andrey Tarasevich


文章< 41 *********************** @ ptn -nntp-reader04.plus.net>

BRG< br*@nowhere.org>写道:
In article <41***********************@ptn-nntp-reader04.plus.net>
BRG <br*@nowhere.org> wrote:
这里有没有人知道作业是否:

a [i] = x [a [i]] ++;

是在C中是合法的,如果是这样,x []中的数组元素是后递增的?

那就是a [i]的旧值或新值是否确定了
中的索引x []后增加数组元素。

我宁愿怀疑结果是未定义的 - 但我是对的吗?
Does anyone here know whether the assignment:

a[i] = x[ a[i] ]++;

is legal in C and, if so, what array element in x[] is post incremented?

That is, does the old or the new value of a[i] determine the index in
x[] of the post incremented array element.

I rather suspect the result is undefined - but am I right?




我自己相信这是同形的:


p = p-> next = q;


问题,所以如果是链表版本是明确定义的,因此是数组版本的

(反之亦然)。我也相信它根本不清楚这是否定义明确,因此程序员不应该使用它,使得问题它是否未定义。有趣的是

但学术上。 :-)

-

现实生活:风河系统Chris Torek

美国犹他州盐湖城(40 °39.22''N,111°50.29''W)+1 801 277 2603

电子邮件:忘了它 http://web.torek.net/torek/index.html

阅读电子邮件就像在垃圾中搜索食物一样,感谢垃圾邮件发送者。



I myself believe that this is isomorphic to the:

p = p->next = q;

problem, so that if the linked-list version is well-defined, so is
the array version (and vice versa). I also believe that it is not
at all clear whether this is well-defined, and therefore programmers
should not use it, making the question "is it undefined" interesting
but academic. :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22''N, 111°50.29''W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.


Chris Torek写道:
Chris Torek wrote:

文章< 41 ********* **************@ptn-nntp-reader04.plus.net>
BRG< br*@nowhere.org>写道:

In article <41***********************@ptn-nntp-reader04.plus.net>
BRG <br*@nowhere.org> wrote:
这里有没有人知道作业是否:

a [i] = x [a [i]] ++;

是在C中是合法的,如果是的话,那么x []中的数组元素是否会增加?

那就是a [i]的旧值或新值是否确定了索引
x []后增加数组元素。

我宁愿怀疑结果是不确定的 - 但我是对的吗?
Does anyone here know whether the assignment:

a[i] = x[ a[i] ]++;

is legal in C and, if so,
what array element in x[] is post incremented?

That is, does the old or the new value of a[i] determine the index in
x[] of the post incremented array element.

I rather suspect the result is undefined - but am I right?



我自己相信这是同形的:

p = p-> next = q;

问题,所以如果链表版本定义明确,那么
阵列版本(反之亦然)。我也相信它根本不清楚这是否定义明确,因此程序员不应该使用它,使问题它是否未定义。有趣
但学术。 : - )



I myself believe that this is isomorphic to the:

p = p->next = q;

problem, so that if the linked-list version is well-defined, so is
the array version (and vice versa). I also believe that it is not
at all clear whether this is well-defined, and therefore programmers
should not use it, making the question "is it undefined" interesting
but academic. :-)




a [i] = x [a [i]] ++问题,

是一个真正的问题来了一个程序

BRG在comp.programming上调试过。

http://groups-beta.google.com/group/...d5a77876d4d991


实际的代码行是

for(i = 0; i< len; i ++)cmp_index [i] = cum [cmp_index [i]] ++;

他哪个改为

for(i = 0; i< len; i ++){

j = cmp_index [i];

cmp_index [i] =暨[j] ++;

}


排序功能无法在我的机器上使用

原件代码行,但它与修复程序有关。


-

pete



The a[i] = x[a[i]]++ problem,
is a real problem which came from a program
that BRG debugged on comp.programming.

http://groups-beta.google.com/group/...d5a77876d4d991

The actual line of code was
for (i=0;i<len;i++) cmp_index[i] = cum[cmp_index[i]]++;
which he changed to
for (i=0;i<len;i++) {
j = cmp_index[i];
cmp_index[i] = cum[j]++;
}

The sort function wouldn''t work on my machine with the
original line of code, but it does with the fix.

--
pete


这篇关于a [i] = x [a [i]] ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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