unsigned comparsions
SuperUser
root at mfci.UUCP
Tue May 3 03:44:55 AEST 1988
Expires:
Followup-To:
Distribution:
Keywords:
In article <11304 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>[They were equivalent. The comparison was |unsigned char| != -1, which
>---provided |char| is shorter than |int|---is indeed always true, in both
>the existing sign preserving system and in the value preserving system in
>the dpANS.]
Oops, I hadn't noticed that the routine was returning an unsigned char, I
only noticed the unsigned. Yes, assuming chars are shorter than ints then
an unsigned char, when zero-padded out to a full int, will never have the
same bit pattern as -1. (I should add that I've always thought that C
routines which return chars or shorts should be avoided, and that such
data types should only be used for arrays and structure members, since C
prefers to deal with full size integers, and using chars and shorts will
at best cost you a bunch of useless sign extensions/zero fills and
truncations, and at worst will cause unexpected results.)
More information about the Comp.lang.c
mailing list