C
Capstar
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
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