本文介绍了"智能"索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi NG,


我正在开发一个软件,它基本上包含一个循环,

,其中包含2个部分。这两个部分基本上是相同的,

但是它们在某些变量中有所不同。所以我将变量从foo0

和foo1更改为foo [2],因此我可以将它们编入索引。这样我可以通过

循环两次,但是在0和1之间切换索引。

这很简单。我是这样做的:


int idx;

for(idx = 0 ;; idx =!idx)

{

do_something_with(foo [idx]);

if(somestatement)break;

}


我的问题是:标准是否保证idx =!idx总是在1或0中产生

?如果我希望编译器循环展开它,

会有用吗?或者这只适用于具有明确的

结束语句而不是休息的for循环?


提前致谢,

马克

Hi NG,

I am developing a piece of software, which contains basicly one loop,
which consinsts of 2 parts. Thos two parts are again basicly the same,
but they deiffer in some variables. So I changed the variables from foo0
and foo1 to foo[2], so I can index them. This way I can run through the
loop two times more, but switch the index between 0 and 1.
This is pretty easy. I did it this way:

int idx;
for(idx=0;;idx=!idx)
{
do_something_with(foo[idx]);
if(somestatement) break;
}

my question is: Does the standard guarantee that idx=!idx always result
in a 1 or a 0? And if I would want the compiler to loop unroll this,
would that work? Or does that only work for a for loop which has a clear
end statement in stead of a break?

Thanks in advance,
Mark

推荐答案




我不知道。 :-\


-

Russell Hanneken






是的。然而,你可以有一个更简单和更清晰的循环:


for(idx = 0; idx< 2; idx ++){

do_something_with(foo [ idx]);

}


(注意几年前空白的短缺结束)


-

回复应该是新闻组

Chuck Falconer度假。



Yes. However you can have a much simpler and clearer loop with:

for (idx = 0; idx < 2; idx++) {
do_something_with(foo[idx]);
}

(Note that the blank shortage ended several years ago)

--
Replies should be to the newsgroup
Chuck Falconer, on vacation.


这篇关于&QUOT;智能&QUOT;索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 18:33