Path: utzoo!attcan!uunet!samsung!usc!ucsd!ucsdhub!hp-sdd!hplabs!hp-ses!hpcuhb!hpda!hpwala!hpavla!gary From: gary@hpavla.AVO.HP.COM (Gary Jackoway) Newsgroups: comp.lang.c Subject: Re: MSC 5.1 bug ?? Message-ID: <9130004@hpavla.AVO.HP.COM> Date: 21 Feb 90 15:23:07 GMT References: <451@fwi.uva.nl> Organization: Hewlett-Packard Avondale Division Lines: 31 > / hpavla:comp.lang.c / linden@fwi.uva.nl (Onno van der Linden) / 12:27 pm Feb 20, 1990 / > Was my brain working OK when I saw the program below,after compiling > with Microsoft C 5.1,produce "Yes" as its output?? > > main() > { > int i = 0; > long l = -1; > > if (l >= (i&1)) puts("Yes"); > else puts("No"); > } > Onno van der Linden > linden@fwi.uva.nl ---------- I verified your result. Further, if you change the int to a short the same thing happens. And the result on UN*X is "No" (at least on HP-UX 7.0). I played around some more and replaced the "l" with "-1". Same thing. The problem seems to be that the binary & operator is returning an unsigned result, even though the manual says "the type of the result is the type of the operators after [the usual arithmetic] conversion". I also put a (short) in front of the "1" and again got "Yes". This appears to me to be a real bug. You can work around the problem by saying "(int)(i&1)" or "(long)(i&1)". Anything to re-sign the result after the "&". You need to do this, of course, only when you are mixing bit-wise operators with signed comparisons. Gary Jackoway