Liste des Groupes | Revenir à c arch |
If START is signed (presumably of type int), so the loop might runBoth yield not very elegant code:
zero times, but never more than INT_MAX times, then
for( unsigned u = START < 0 ? 0 : START + 1u; u > 0 && u--; ){
// Do something with data[i]
}
If START is unsigned, so in all cases the loop must run at
least once, then
unsigned u = START;
do {
// Do something with data[i]
} while( u > 0 && u-- );
(Yes I know the 'u > 0' expressions can be replaced by just 'u'.)
The optimizer should be smart enough to realize that if 'u > 0'
is true then the test 'u--' will also be true. The same should
hold if 'u > 0' is replaced by just 'u'.
(Disclaimer: code not compiled.)
Les messages affichés proviennent d'usenet.