Is something wrong with the compiler ?

Henry Spencer henry at zoo.toronto.edu
Fri Sep 28 02:53:48 AEST 1990


In article <143014 at sun.Eng.Sun.COM> eager at ringworld.Eng.Sun.COM (Michael J. Eager) writes:
>>      printf(" Maxint : %d\na = %d\n", ( int )(( unsigned ) ~0 >> 1 ) , 
>The assignment of a = ~0 will make a = -1.  When this is shifted
>right by one bit, and the sign bit is set to zero, a becomes
>MAXINT, which you then converted to unsigned and then int...

Careful...  Casts bind tighter than binary operators; the unsigned
conversion is being done *before* the shift.
-- 
TCP/IP: handling tomorrow's loads today| Henry Spencer at U of Toronto Zoology
OSI: handling yesterday's loads someday|  henry at zoo.toronto.edu   utzoo!henry



More information about the Comp.lang.c mailing list