Newsgroups: comp.lang.c Path: utzoo!henry From: henry@zoo.toronto.edu (Henry Spencer) Subject: Re: Signed to unsigned comparison Message-ID: <1991Mar24.001308.12852@zoo.toronto.edu> Date: Sun, 24 Mar 1991 00:13:08 GMT References: <40472@cup.portal.com> Organization: U of Toronto Zoology In article <40472@cup.portal.com> PLS@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@zoo.toronto.edu utzoo!henry