Path: utzoo!mnetor!uunet!husc6!purdue!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: unsigned comparsions Message-ID: <11304@mimsy.UUCP> Date: 1 May 88 22:56:04 GMT References: <12578@brl-adm.ARPA> <1988Mar25.172355.348@utzoo.uucp> <375@m3.mfci.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 33 In article <375@m3.mfci.UUCP> root@mfci.UUCP (SuperUser) writes: >No, these two programs are not equivalent. [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.] >When comparing an unsigned [integer] to a signed integer, the signed >integer is first cast to unsigned (which results in no change in the >bit pattern), then the comparison is performed. With the insertion I have made (which was implied, but given dpANS rules one must be explicit), this is correct. >since octal and hex constants are signed in C, In K&R. In dpANS C, some octal and hex constants are unsigned, as are some integer constants. >... People are often surprised by the fact that an expression like >(u > -1) is always false when u is unsigned, since the -1 is first >cast to unsigned, whereupon it becomes the largest possible unsigned. Again, this is correct in both systems, with the proviso that |u| is |unsigned int|, not |unsigned char| or |unsigned short|. Under dpANS rules, however, if |u| is |unsigned char| and |char| is shorter than |int|, it will be always true; if |u| is |unsigned short| the test will be either always true or always false, depending on the size of |short| vs |int|. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris