Liste des Groupes | Revenir à c arch |
Bernd Linsel wrote:
>On 05.09.24 19:04, Terje Mathisen wrote:>
>One 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:
>
for (unsigned u = start; (u & TOPBIT) == 0; u--)
What about:
>
for (unsigned u = start; u != ~0u; --u)
I like that one!
>...>
>
or even
>
for (unsigned u = start; (int)u >= 0; --u)
That is the one that I've actually been using, i.e. casting to the
corresponding signed type.
Les messages affichés proviennent d'usenet.