Sujet : Re: Computer architects leaving Intel...
De : kegs (at) *nospam* provalid.com (Kent Dickey)
Groupes : comp.archDate : 14. Sep 2024, 20:57:04
Autres entêtes
Organisation : provalid.com
Message-ID : <vc4pqg$1l8mq$1@dont-email.me>
References : 1 2 3 4
User-Agent : trn 4.0-test76 (Apr 2, 2001)
In article <
vc4mgj$1khmk$1@dont-email.me>,
Thomas Koenig <
tkoenig@netcologne.de> wrote:
Kent Dickey <kegs@provalid.com> schrieb:
>
When you write code working on signed numbers and do something like:
>
(a < 0) || (a >= max)
>
Then the compiler realizes if you treat 'a' as unsigned, this is just:
>
(unsigned)a >= max
>
For which definition of a and max exactly?
>
It coertainly does not do so for
>
_Bool foo(int a, int max)
{
return (a < 0) || (a >= max);
}
Sorry, I should have made it clear for max >= 0 (but not necessarily an
unsigned variable), and for my code, a constant, which is how the
compiler knows it's positive . I have this in my code all the time to
validate function inputs--a negative number is bad, and a number beyond
a certain reasonable value is bad. And I let the compiler optimize the
check to (unsigned)a >= (unsigned)max.
Kent