当i == ii时,mystr [i] = mystr [ii]是否会成为一个问题 [英] Can mystr[i]=mystr[ii] be a problem when i==ii

查看:100
本文介绍了当i == ii时,mystr [i] = mystr [ii]是否会成为一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个使用上面代码的字符串解析函数。 i和ii在

中是相同的,但随着我的循环继续,ii增加更多。我可以做

if(ii!= i)

mystr [i] = mystr [ii];


但是我想要限制不必要的代码。



I have a string parsing function which uses above code. i and ii are same at
first but as my loop goes on ii is incremented more. I could do
if (ii!=i)
mystr[i]=mystr[ii];

but I want to limit unnecessary code.

推荐答案

乔说:

>


我有一个使用上面代码的字符串解析函数。 i和ii最初是相同的
,但随着我的循环继续,ii增加更多。我可以

如果(ii!= i)

mystr [i] = mystr [ii];


但是我想限制不必要的代码。
>

I have a string parsing function which uses above code. i and ii are
same at first but as my loop goes on ii is incremented more. I could
do if (ii!=i)
mystr[i]=mystr[ii];

but I want to limit unnecessary code.



不,你不需要测试。不过,干得好,因为它的价值不如听起来那么明显。相关规则是:


在上一个和下一个序列点之间,一个对象应该具有

,其存储值最多只能通过评估一次修改一次

表达式。此外,先前的值只能访问

确定要存储的值。


您的代码(如上所述)遵守此规则,并且没有问题。


不难想象类似的代码可能会失败。

例如:

mystr [i] = mystr [i ++]; / *坏! * /


会违反上述要求。


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上述域名中, - www。

No, you don''t need the test. Well done for asking, though, because it''s
not as obvious as it sounds. The relevant rule is:

"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."

Your code (as written above) obeys this rule, and there is no problem.

It is not difficult to imagine similar code which could fail, however.
For example:

mystr[i] = mystr[i++]; /* BAD! */

would violate the requirement quoted above.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.


Joe写道:
Joe wrote:

>

我有一个使用上面代码的字符串解析函数。 i和ii

起初相同,但随着我的循环继续,ii增加更多。

我可以做

if(ii!= i)

mystr [i] = mystr [ii];


但我想限制不必要的代码。
>
I have a string parsing function which uses above code. i and ii
are same at first but as my loop goes on ii is incremented more.
I could do
if (ii!=i)
mystr[i]=mystr[ii];

but I want to limit unnecessary code.



我看不到''上面代码''。


-

< http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>

< http://www.securityfocus.com/columnists/423>

< http://www.aaxnet.com/editor/edit043.html>

< http://kadaitcha.cx/vista/dogsbreakfast/index.html> <美联航网络上的
cbfalconer


-

通过 http://www.teranews.com

I see no ''above code''.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com


CBFalconer < cb ******** @ yahoo.comwrote:

使用以上代码我的意思是:

mystr [i] = mystr [ii];
CBFalconer <cb********@yahoo.comwrote:
With "above code" I mean:
mystr[i]=mystr[ii];


这篇关于当i == ii时,mystr [i] = mystr [ii]是否会成为一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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