Signed to unsigned comparison
Henry Spencer
henry at zoo.toronto.edu
Sun Mar 24 10:13:08 AEST 1991
In article <40472 at cup.portal.com> PLS at cup.portal.com (Paul L Schauble) writes:
>What should a compiler do with the comparison in this example:
> unsigned int a;
>
> a = 5;
> if (a > -1) ....
The infamous "usual arithmetic conversions" apply. The -1 is converted to
`unsigned int', probably giving something like 65535 or 2147483647, and
then the comparison is done, probably not giving the result you expect.
What a compiler *should* do is give you a warning about this.
--
"[Some people] positively *wish* to | Henry Spencer @ U of Toronto Zoology
believe ill of the modern world."-R.Peto| henry at zoo.toronto.edu utzoo!henry
More information about the Comp.lang.c
mailing list