F
Frederick Gotham
I just want to clarify my understanding of arithmetic and comparison
between two different integer types.
Phase (1): Integer Promotion
----------
All of the following types always get promoted to "signed int":
signed char
signed short
All of the following types get promoted to "signed int" if it has
sufficient range on the platform; otherwise, they go to "unsigned int".
char
unsigned char
unsigned short
Phase (2): Now working with "int" and upwards
----------
Now everything is one of the following types:
signed int
unsigned int
signed long
unsigned long
That leaves us with 10 possibilities. The first four are straight-forward:
(1) signed int + signed int
(2) unsigned int + unsigned int
(3) signed long + signed long
(4) unsigned long + unsigned long
The following involve the same type, but different signedness. Am I right
in thinking that they both become "unsigned int" in (5), and both become
"unsigned long" in (6)?
(5) signed int + unsigned int
(6) signed long + unsigned long
Then there's two different types which have the same signedness. Would I be
right in thinking that they both become signed long in (7), and both become
unsigned long in (8)?
(7) signed int + signed long
(8) unsigned int + unsigned long
Now here's the dirty ones which I'm least sure about. What happens in (9)
and (10)? Are (9) and (10) implementation-specific depending on whether
numeric_limits<long>::digits > numeric_limits<int>::digits?
(9) signed int + unsigned long
(10) unsigned int + signed long
between two different integer types.
Phase (1): Integer Promotion
----------
All of the following types always get promoted to "signed int":
signed char
signed short
All of the following types get promoted to "signed int" if it has
sufficient range on the platform; otherwise, they go to "unsigned int".
char
unsigned char
unsigned short
Phase (2): Now working with "int" and upwards
----------
Now everything is one of the following types:
signed int
unsigned int
signed long
unsigned long
That leaves us with 10 possibilities. The first four are straight-forward:
(1) signed int + signed int
(2) unsigned int + unsigned int
(3) signed long + signed long
(4) unsigned long + unsigned long
The following involve the same type, but different signedness. Am I right
in thinking that they both become "unsigned int" in (5), and both become
"unsigned long" in (6)?
(5) signed int + unsigned int
(6) signed long + unsigned long
Then there's two different types which have the same signedness. Would I be
right in thinking that they both become signed long in (7), and both become
unsigned long in (8)?
(7) signed int + signed long
(8) unsigned int + unsigned long
Now here's the dirty ones which I'm least sure about. What happens in (9)
and (10)? Are (9) and (10) implementation-specific depending on whether
numeric_limits<long>::digits > numeric_limits<int>::digits?
(9) signed int + unsigned long
(10) unsigned int + signed long