棘手的任务状态 [英] tricky assignment statemenent

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

问题描述

p = p-> next = q;


为什么未定义?

operator" ="是右关联的,即p = p-> next = q;是

相当于p =(p-> next = q);

我认为对序列点的另一种解释是:在2
$之间b $ b序列点变量不能修改两次。在p = p-> next =

q;"," p-> next被修改一次,p被修改。被修改一次。 (假设我们使用

另一个指针k使得k = p-> next然后p = p-> next = q;

变为p = k = q。显然,k和p分别被修改为
。)

p = p->next = q;

Why it is undefined?
operator "=" is right-associative i.e. "p = p->next = q;" is
equivalent to "p = (p->next = q);
And I think another interpretation of sequence point is: between 2
sequence point a variable cannot be modified twice. In "p = p->next =
q;", "p->next" is modified once, "p" is modified once. (Let say we use
another pointer "k" such that "k=p->next" and then "p = p->next = q;"
become "p = k = q". Obviously the "k" and "p" are modified once
individually.)

推荐答案

在文章< d0 ************************** @ posting.google.com> ,
cc****@hotmail.com (ccwork)写道:
In article <d0**************************@posting.google.com >,
cc****@hotmail.com (ccwork) wrote:
p = p-> next = q;

为什么它未定义?
operator" ="是右关联的,即p = p-> next = q;相当于p =(p-> next = q);
我认为对序列点的另一种解释是:在2个序列点之间,一个变量不能被修改两次。在p = p-> next =
q;"," p-> next被修改一次,p被修改。被修改一次。 (假设我们使用另一个指针k,使得k = p-> next然后p = p-> next = q;
变为 p = k = q。显然,k和p单独修改一次。)
p = p->next = q;

Why it is undefined?
operator "=" is right-associative i.e. "p = p->next = q;" is
equivalent to "p = (p->next = q);
And I think another interpretation of sequence point is: between 2
sequence point a variable cannot be modified twice. In "p = p->next =
q;", "p->next" is modified once, "p" is modified once. (Let say we use
another pointer "k" such that "k=p->next" and then "p = p->next = q;"
become "p = k = q". Obviously the "k" and "p" are modified once
individually.)




C中没有规则评估操作数的顺序。


q的值最终将存储到p中。在将q存储到p之前或之后,是否可以读取p中的p-> next

?如果您在C

标准中找到了这个定义的地方,那就没问题。祝你好运。



There are no rules in C in which order operands are evaluated.

The value of q will eventually be stored into p. Will the p in "p->next"
be read before or after q is stored into p? If you find where in the C
Standard this is defined, then fine. Good luck looking for it.


Christian Bau写道:
Christian Bau wrote:
文章< d0 ************ **************@posting.google.com>,
cc **** @ hotmail.com (ccwork)写道:
In article <d0**************************@posting.google.com >,
cc****@hotmail.com (ccwork) wrote:
p = p-> next = q;

为什么它未定义?
operator" ="是右关联的,即p = p-> next = q;相当于p =(p-> next = q);
我认为对序列点的另一种解释是:在2个序列点之间,一个变量不能被修改两次。在p = p-> next
= q;"," p-> next被修改一次,p被修改。被修改一次。 (假设我们
使用另一个指针k使得k = p-> next然后p = p-> next =
q;变为p显然,k和p单独修改一次。)
C中没有规则来评估操作数的顺序。

p = p->next = q;

Why it is undefined?
operator "=" is right-associative i.e. "p = p->next = q;" is
equivalent to "p = (p->next = q);
And I think another interpretation of sequence point is: between 2
sequence point a variable cannot be modified twice. In "p = p->next = q;", "p->next" is modified once, "p" is modified once. (Let say we use another pointer "k" such that "k=p->next" and then "p = p->next = q;" become "p = k = q". Obviously the "k" and "p" are modified once
individually.)
There are no rules in C in which order operands are evaluated.

The value of q will eventually be stored into p. Will the p in



" p-> next"在q存储到p之前或之后读取?


"p->next" be read before or after q is stored into p?




之前。在某些情况下,有关于表达式评估的相对

顺序的隐含规则。让我们来看一个简单的例子:


p = p + 1;


根据你的逻辑,这将是未定义的。然而,6.5.2得到了

我们摆脱困境:


6.5表达式

..

.. 2在上一个和下一个序列点之间,一个对象

..应该通过

..表达式的评估最多修改一次它的存储值。此外,只能访问先前值

..以确定要存储的值。


表达式''p + 1''表示' '要存储的价值''。在''p

+ 1''中,p代表''先前值''。在这里,p''只能访问

确定要存储的值''。


简单地提到''先前值''会产生隐含的,部分

操作数评估顺序。在评估''之前

值''之前,不得修改p。


表达式:


p = p-> next = q;


评估与上述相同,并且是定义的行为。

''p-> next = q''是''要存储的值''。由于p在表达式中被修改了

,因此p-> next中的p是''先前值''。由于

p-> next是表达式''p-> next = q''的参与者(''值'

存储'') ,很明显''先前的值[只]只能访问

来确定要存储的值''。


它*是*定义的行为。不管是不是好风格都是另一回事。

Mark F. Haigh
mf ***** @ sbcglobal.net



Before. In some cases there are implicit rules about the relative
order of evaluation of expressions. Let''s take the trivial example of:

p = p + 1;

According to your logic, this would be undefined. However, 6.5.2 gets
us off the hook:

6.5 Expressions
..
.. 2 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 accessed only to determine the value to be stored.

The expression ''p + 1'' represents ''the value to be stored''. Within ''p
+ 1'', p represents ''the prior value''. Here, p is ''accessed only to
determine the value to be stored''.

Simply mentioning ''the prior value'' creates an implicit, partial
operand evaluation order. p must not be modified until its ''prior
value'' is evaluated.

The expression:

p = p->next = q;

Is evaluated much the same as the above, and is defined behavior.
''p->next = q'' is the ''value to be stored''. Since p is being modified
in the expression, the p in p->next is the ''prior value''. Since
p->next is a participant in the expression ''p->next = q'' (the ''value to
be stored''), it''s clear that ''the prior value [is] accessed only to
determine the value to be stored''.

It *is* defined behavior. Whether or not it is good style is another
matter altogether.
Mark F. Haigh
mf*****@sbcglobal.net


文章< 11 ******* ***************@f14g2000cwb.googlegroups .com> ;,
mf *** **@sbcglobal.net 写道:
In article <11**********************@f14g2000cwb.googlegroups .com>,
mf*****@sbcglobal.net wrote:
表达式:

p = p-> next = q;
<评估与上述评估大致相同,并且是定义的行为。
''p-> next = q''是''要存储的值''。由于p在表达式中被修改,p-> next中的p是''先前值''。由于
p-> next是表达式''p-> next = q''的参与者(''要存储的值''),所以'很明显' '先前值[仅]访问
确定要存储的值''。


先前的值绝对不会被访问以确定要存储的

值。它被_also_访问以确定

的另一个内存位置(& p-> next)的地址,其内容也被修改。

这里有两个任务,两个修改后的内存位置。

如果不读取p,你将如何确定第二个位置?

它是*定义的行为。是否它是一个好的风格是另一个完全的事情。
The expression:

p = p->next = q;

Is evaluated much the same as the above, and is defined behavior.
''p->next = q'' is the ''value to be stored''. Since p is being modified
in the expression, the p in p->next is the ''prior value''. Since
p->next is a participant in the expression ''p->next = q'' (the ''value to
be stored''), it''s clear that ''the prior value [is] accessed only to
determine the value to be stored''.
The prior value is most definitely _not_ only accessed to determine the
value to be stored. It is _also_ accessed to determine the address of
another memory location (&p->next) whose contents is also modified.
There are two assignments here, two memory locations that are modified.
How would you determine the second location without reading p?

It *is* defined behavior. Whether or not it is good style is another
matter altogether.




绝对没有定义。类似于a [i] = i ++; :我被修改了。访问

先前值以确定存储在i中的新值。我也是为了另一个目的而访问
:确定一个内存位置

将存储i ++的值。未定义的行为。



Absolutely not defined. Similar to "a [i] = i++; ": i is modified. The
prior value is accessed to determine the new value stored in i. i is
also accessed for another purpose: to determine a memory location where
the value of i++ will be stored. Undefined behavior.


这篇关于棘手的任务状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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