关于“++”的问题 [英] question about "++"
问题描述
给出表达式:
while(isaspace(c = * s ++))
x + 1;
( s是一个数组)
''s'的增量是否发生在'x + 1'之后?是评估,或在
之后,s的内容被分配给c?是否存在这种增量发生时的一般规则
? (我知道c
= ++ * s的增量会在分配之前发生,因此我的猜测是相同的
将适用于之后 ; scenerio,但不确定)。
谢谢。
Given the expression:
while (isaspace(c = *s++))
x+1;
(s is an array)
Does the increment to ''s'' occur after "x+1" is evaluated, or after
the content of s is assigned to c? Is there a general rule as to when
this type of increment occurs? ( I understand that the increment in "c
= ++*s" occurs immediately before assignment, so my guess is the same
would apply in the "after" scenerio, but not sure).
thank you.
推荐答案
mdh说:
mdh said:
给出表达式:
while(isaspace(c = * s ++))
x + 1;
(s是一个数组)
''s'的增量是否发生在x + 1之后?评估,
Given the expression:
while (isaspace(c = *s++))
x+1;
(s is an array)
Does the increment to ''s'' occur after "x+1" is evaluated,
否,之前。
No, before.
或之后
s的内容被分配给c?
or after
the content of s is assigned to c?
也许。
这是一个可能的订购:
(1 )分配* s到c
(2)增量s
这是另一个:
( 1)将* s分配给一个温度
(2)增量s
(3)将温度分配给c
这里另一个:
(1)增量s
(2)分配*(s - 1)到c
无论如何,在x + 1发生之前,一切都已完成并且除尘。
在一个序列点和下一个序列点之间,编译器有相当多的
$ b关于它什么时候做什么的自由。 (在序列点之间,它b / b
的自由度相当低 - 只有严格符合b $ b b b的程序才能说明它已经这样做了。)< br $>
-
Richard Heathfield
Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk
电子邮件:rjh在上述域名, - www。
Maybe.
Here is one possible ordering:
(1) assign *s to c
(2) increment s
Here''s another:
(1) assign *s to a temp
(2) increment s
(3) assign the temp to c
Here''s another:
(1) increment s
(2) assign *(s - 1) to c
In any event, all is definitely done and dusted before x+1 happens.
Between one sequence point and the next, the compiler has considerable
freedom with regard to what it does when. (Across sequence points, it
has rather less freedom - it can only mess about if a strictly
conforming program can''t tell that it has done so.)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
5月29日下午6:41,Richard Heathfield< ; r ... @ see.sig.invalidwrote:
On May 29, 6:41 pm, Richard Heathfield <r...@see.sig.invalidwrote:
mdh说:>
while(isaspace(c = * s ++) )
mdh said:>
while (isaspace(c = *s++))
x + 1;
x+1;
>
>
s的增量是否发生在x + 1之后?被评估,
Does the increment to ''s'' occur after "x+1" is evaluated,
不,之前。
No, before.
或之后
s的内容被分配给c?
or after
the content of s is assigned to c?
也许。
这是一个可能的订购:
Maybe.
Here is one possible ordering:
无论如何,在x + 1发生之前,一切都已完成并且已经粉碎。
In any event, all is definitely done and dusted before x+1 happens.
谢谢理查德。这解释了错误。在我想要它之前,我已经增加了
。
thank you Richard. That explains a "bug" I had with s incrementing
before I wanted it to.
5月30日下午1点32分,mdh< m ... @ comcast.netwrote:
On May 30, 1:32 pm, mdh <m...@comcast.netwrote:
给出表达式:
while(isaspace(c = * s ++))
x + 1;
(s是一个数组)
Given the expression:
while (isaspace(c = *s++))
x+1;
(s is an array)
如果s是一个数组,那么这段代码有一个约束
违规,因为数组无法递增。
您的意思是(* s)++?
If s is an array then this code has a constraint
violation, as arrays cannot be incremented.
Did you mean (*s)++ ?
这篇关于关于“++”的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!