MSC 5.1 bug ??

Gary Jackoway gary at hpavla.AVO.HP.COM
Thu Feb 22 02:23:07 AEST 1990


> / hpavla:comp.lang.c / linden at 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 at 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



More information about the Comp.lang.c mailing list