When performing integer (not int) arithmetic with integer operands of rank 
lower than int, the operands will be promoted to either int or unsigned int.  
When adding two short or two char or a char and a short, both operands will be 
promoted to int before the addition and the result will be an int.

When any operand is of rank greater or equal to int, all operands are promoted 
to the highest rank in the expression and the arithmetic is performed on that 
type.

Operands of rank greater than int are not demoted to int.  The expression in 
question involves shifting an unsigned long long and the result will be an 
unsigned long long.  When the result is assigned to the left operand, it will 
be converted to the type of that operand.  This is true regardless of the type 
of the left operand.


----- Original Message -----
From: "Bernd Oppolzer" <bernd.oppol...@t-online.de>
To: IBM-MAIN@LISTSERV.UA.EDU
Sent: Monday, July 22, 2013 12:18:25 PM
Subject: Re: Looking for help with an obscure C integer problem

That is another case, because the right side operands are not ints.

For ints, I saw references that all operands are promoted to ints,
if they can be represented as an int (that is true for chars, shorts etc.).

Don't know for sure about longs, for example; if long differs in size
from int, and there are longs on the right side, will they be promoted 
(that is: truncated)
to int, if there is an int on the left side, or will they be evaluated as
longs? That's the key question IMHO, and there should be a reference
in the C language description that makes it clear without doubt - but I
did not yet find such a reference - had not much time to look for it.

(IMO, it would be no good language design if such a core question
is left to the compiler builder - I don't believe it is so).

Kind regards

Bernd



Am 22.07.2013 18:27, schrieb retired-mainfra...@q.com:
> The right operand in this case is the result of evaluating the expression.  
> The quoted text is not meant to imply that operands are converted before the 
> right hand expression is evaluated.  If that were the case, then
>     int x = 14.0/2.1;
> would evaluate to 7 which is demonstrably not the case.
>

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

Reply via email to