Liste des Groupes | Revenir à c arch |
Bernd Linsel <bl1-thispartdoesnotbelonghere@gmx.com> writes:In a code review, I would reject that - and all the other nonsenses suggested here as a way to force all loop indices to be unsigned types as though that rule was the 11th commandment.On 05.09.24 19:04, Terje Mathisen wrote:This is the form we use most when we needOne of my alternatives are>
>
unsigned u = start; // Cannot be less than zero
if (u) {
u++;
do {
u--;
data[u]...
while (u);
}
>
This typically results in effectively the same asm code as the signed
version, except for a bottom JGE (Jump (signed) Greater or Equal instead
of JA (Jump Above or Equal, but my version is far more verbose.
>
Alternatively, if you don't need all N bits of the unsigned type, then
you can subtract and check if the top bit is set in the result:
>
%G�%@| for (unsigned u = start; (u & TOPBIT) == 0; u--)
>
Terje
>
What about:
>
for (unsigned u = start; u != ~0u; --u)
to work in reverse.
Les messages affichés proviennent d'usenet.