S
spibou
On 6.3.1.1 of N1124 we read:
If an int can represent all values of the
original type, the value is converted to
an int; otherwise, it is converted to an
unsigned int.
A few lines above that we read:
The following may be used in an expres-
sion wherever an int or unsigned int may
be used:
So the first quote refers only to objects which can be
represented as an (unsigned) int , right ?
1. So why do integer promotion rules exist ?
After having read http://www.quut.com/c/rat/c2.html#3-2-1-1
I think I can guess at the answer. Traditional
(meaning before the first standard) implementations
had types smaller than int so they had to have *some*
promotion rules for situations where a type
smaller than int encountered across an operator
a type which was int. So the standard simply chose
between the 2 historical integer promotion practices.
2. Why do promotion rules apply when using the ~
operator ?
3. Which promotion rules apply when one of the
operands is (long) long (unsigned) int ?
Spiros Bousbouras
If an int can represent all values of the
original type, the value is converted to
an int; otherwise, it is converted to an
unsigned int.
A few lines above that we read:
The following may be used in an expres-
sion wherever an int or unsigned int may
be used:
So the first quote refers only to objects which can be
represented as an (unsigned) int , right ?
1. So why do integer promotion rules exist ?
After having read http://www.quut.com/c/rat/c2.html#3-2-1-1
I think I can guess at the answer. Traditional
(meaning before the first standard) implementations
had types smaller than int so they had to have *some*
promotion rules for situations where a type
smaller than int encountered across an operator
a type which was int. So the standard simply chose
between the 2 historical integer promotion practices.
2. Why do promotion rules apply when using the ~
operator ?
3. Which promotion rules apply when one of the
operands is (long) long (unsigned) int ?
Spiros Bousbouras