From mboxrd@z Thu Jan 1 00:00:00 1970 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-reply-to: Your message of "Thu, 22 Apr 2010 23:15:51 +0200." <20100422211551.GA987@polynum.com> References: <20100422175033.GA6247@polynum.com> <87d97130a41364706523e641fe0dd372@plan9.bell-labs.com> <20100422193236.GA2388@polynum.com> <20100422200740.49F7D5B73@mail.bitblocks.com> <20100422211551.GA987@polynum.com> From: Bakul Shah Date: Thu, 22 Apr 2010 15:49:11 -0700 Message-Id: <20100422224911.F14615B73@mail.bitblocks.com> Subject: Re: [9fans] BUG!!! in Plan9 compiler! Topicbox-Message-UUID: 0c7f90d2-ead6-11e9-9d60-3106f5b1d025 On Thu, 22 Apr 2010 23:15:51 +0200 tlaronde@polynum.com wrote: > This is: signed long + signed long + unsigned char. > Do you mean that there is first promotion : > > 1) unsigned char is promoted to unsigned int (A6.1). As per C89 in this case the unsigned char value should be promoted to a *signed* int value. The sum will be of type signed int and so the division will do the right thing. In kencc case it seems the sum has type unsigned int for some reason and further, the signed divisor (2) is promoted to an unsigned int. Seems like a bug. Now that you know the problem, you can work around it by setting type smallnumber to a signed char (since its range is 0..64 this should just work with either compiler). > And when I do first assignment, there is only promotion (since no > operator is here). There is promotion since you did += but it doesn't matter. In C, a variable has a static type and you can't override this type by any assignment. > Yielding the correct value in x2, that is then > divided (or shifted) by 2, hence signed, and no problem? Yes.