On Thu, 22 Apr 2010 23:15:51 +0200 tlaro...@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.

Reply via email to