In a C expression where unsigned int and signed int are present, which type will be promoted to what type?
c, integer-promotion
Solution
I think the following answers your question:
6.3.1.3 Signed and unsigned integers
1 When a value with integer type is converted to another integer type other than _Bool, if the value can be represented by the new type, it is unchanged.
2 Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type.
3 Otherwise, the new type is signed and the value cannot be represented in it; either the result is implementation-defined or an implementation-defined signal is raised.
Problem
I have a query about data type promotion rules in C language standard. The C99 says that: C integer promotions also require that "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." My questions is in case of a C language expression where `unsigned int` and `signed int` are present, which type will be promoted to what type? E.g. `int` cannot represent all the values of the `unsigned int` (values larger than `MAX_INT` values) whereas `unsigned int` cannot represent the -ve values, so what type is promoted to what in such cases?