Integral conversions

Unsigned integer to unsigned integer or signed integer to signed integer
If the types are identical, there is no change. If the types are of a different size, and the value can be represented by the new type, the value is not changed; if the value cannot be represented by the new type, truncation or sign shifting will occur.
Signed integer to unsigned integer
The resulting value is the smallest unsigned integer type congruent to the source integer. If the value cannot be represented by the new type, truncation or sign shifting will occur.
Unsigned integer to signed integer
If the signed type is large enough to hold the original value, there is no change. If the value can be represented by the new type, the value is not changed; if the value cannot be represented by the new type, truncation or sign shifting will occur.
Signed and unsigned character types to integer
If the original value can be represented by int, it is represented as int. If the value cannot be represented by int, it is promoted to unsigned int.
Wide character type wchar_t to integer
If the original value can be represented by int, it is represented as int. If the value cannot be represented by int, it is promoted to the smallest type that can hold it: unsigned int, long, or unsigned long.
Signed and unsigned integer bit field to integer
If the original value can be represented by int, it is represented as int. If the value cannot be represented by int, it is promoted to unsigned int.
Enumeration type to integer
If the original value can be represented by int, it is represented as int. If the value cannot be represented by int, it is promoted to the smallest type that can hold it: unsigned int, long, or unsigned long. Note that an enumerated type can be converted to an integral type, but an integral type cannot be converted to an enumeration.


[ Top of Page | Previous Page | Next Page | Contents | Index ]