On Monday, December 30, 2002, at 06:31 AM, Johan Knol wrote:
>>> However: e.g. "long = int + int" was always done in 16bits. I wonder
>>> that has never been noticed.
>> Because it is correct. 'int' is the smallest common type for
>> the fact that it is being assigned to a long really doesn't matter!
> Hmm. Than how about "int = char + char" or "int = short + short". Gcc
> promote the operands and not the result.
Out of K&R, page 44:
* If either operand is a long double, convert the other to long double.
* Otherwise, if either operand is a double, convert the other to double.
* Otherwise, if either operand is a float convert the other to a float.
* Otherwise, convert char and short to int.
* Then, if either operand is long, convert the other to long.
So the rules promote operands to int, but do not automatically promote
past that. I guess the logic is that an int fits into a machine word,
so it's cheap to promote up to it. However, promoting any further is
expansive and should not be done implicitly.