On Mon, 14 Dec 2015 13:07:48 -0500 Random832 <[email protected]> wrote:
> Mattias Andrée <[email protected]> writes: > > I think this patch should be included. But I don't see > > how it is of substance. It will never occur with two's > > complement or ones' complement. Only, signed magnitude > > representatiion. Any sensible C compiler for POSIX > > systems will only use two's complement; otherwise > > int[0-9]*_t cannot be implemented. > > I had assumed that comparing an unsigned value with a > negative number resulted in a comparison that is > unconditionally false, rather than converting one to the > type of the other. Maybe that's because I've gotten too > used to non-C languages that don't have fixed-size > integers. > > Sorry for the confusion. > > C is a complicated language, and you always get stuck in the mind-set for the language you most recently used for an extended time. At comparison integers are cast to match each others types. This can see confusing in the case of a inequality comparison with mixed signs. But, it does not matter whether the comparands are cast to signed or unsigned. But `char` is the most confusing of all, it is always cast to `int`, which makes it very peculiar because it can either be signed or unsigned, and the result of a cast depends on the sign. For example (char)255 == -1 may or may not be true.
pgpR8ghNTQTu7.pgp
Description: OpenPGP digital signature
