Liste des Groupes | Revenir à c arch |
In article <vc4mgj$1khmk$1@dont-email.me>,And that's the information the compiler was missing to optimize foo() in the same way:
Thomas Koenig <tkoenig@netcologne.de> wrote:Kent Dickey <kegs@provalid.com> schrieb:Sorry, I should have made it clear for max >= 0 (but not necessarily an
>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);
}
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
Les messages affichés proviennent d'usenet.