Type conversions are implementation dependent. Tables on this page summarize type conversions of arithmetic types. Arithmetic types include signed and unsigned integral types (char, int, short and long) in addition to float, double, and long double types.
Type Conversions--Signed Integer Types | |||||
To: |
signed char | signed short | signed int | signed long | signed long long |
---|---|---|---|---|---|
From: |
|||||
signed char | None | Sign extend | Sign extend | Sign extend | Sign extend |
signed short | Preserve low-order bytes | None | sign extend | sign extend | sign extend |
signed int | Preserve low-order bytes | Preserve low-order bytes | None | Preserve bit pattern | sign extend |
signed long | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | None | sign extend |
signed long long | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | None |
unsigned char | Preserve bit pattern: high-order bit becomes sign bit | Zero extend | Zero extend | Zero extend | Zero extend |
unsigned short | Preserve low-order bytes | Preserve bit pattern: high-order bit becomes sign bit | Zero extend | Zero extend | Zero extend |
unsigned int | Preserve low-order bytes | Preserve low-order bytes | Preserve bit pattern: high-order bit becomes sign bit | Preserve bit pattern: high-order bit becomes sign bit | Zero extend |
unsigned long | Preserve low-order bytes | Preserve low-order bytes | Preserve bit pattern: high-order bit becomes sign bit | Preserve bit pattern: high-order bit becomes sign bit | Zero extend |
unsigned long long | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | Preserve bit pattern: high-order bit becomes sign bit |
float | Convert to int, and convert int to signed char | Convert to int, and convert int to signed short | Truncate at decimal. if result is too large for int, result is undefined | Truncate at decimal. if result is too large for long, result is undefined | Truncate at decimal. if result is too large for long long, result is undefined |
double | Convert to int, and convert int to signed char | Convert to int, and convert int to signed short | Truncate at decimal. if result is too large for int, result is undefined | Truncate at decimal. if result is too large for long, result is undefined | Truncate at decimal. if result is too large for long long, result is undefined |
long double | Convert to int, and convert int to signed char | Convert to int, and convert int to signed short | Truncate at decimal. if result is too large for int, result is undefined | Truncate at decimal. if result is too large for long, result is undefined | Truncate at decimal. if result is too large for long long, result is undefined |
Type Conversions--Unsigned Integer Types | |||||
To: |
unsigned char | unsigned short | unsigned int | unsigned long | unsigned long long |
---|---|---|---|---|---|
From: |
|||||
signed char | Preserve bit pattern: sign function of sign bit lost | Sign extend to short, and convert to unsigned short | Sign extend to int, and convert int to unsigned int | Sign extend to long, and convert long to unsigned long | Sign extend to long long, and convert long long to unsigned long long |
short | Preserve low-order byte | Preserve bit pattern: sign function of sign bit lost | Sign extend to int, and convert int to unsigned int | Sign extend to long, and convert long to unsigned long | Sign extend to long long, and convert long long to unsigned long long |
int | Preserve low-order byte | Preserve low-order byte | Preserve bit pattern: sign function of sign bit lost | Preserve bit pattern: sign function of sign bit lost | Sign extend to long long, and convert long long to unsigned long long |
long | Preserve low-order byte | Preserve low-order byte | Preserve bit pattern: sign function of sign bit lost | Preserve bit pattern: sign function of sign bit lost | Sign extend to long long, and convert long long to unsigned long long |
long long | Preserve low-order byte | Preserve low-order byte | Preserve low-order byte | Preserve low-order byte | Preserve bit pattern: sign function of sign bit lost |
unsigned char | None | Zero extend | Zero extend | Zero extend | Zero extend |
unsigned short | Preserve low-order byte | None | Zero extend | Zero extend | Zero extend |
unsigned int | Preserve low-order bytes | Preserve low-order bytes | None | Preserve bit pattern | Zero extend |
unsigned long | Preserve low-order bytes | Preserve low-order bytes | Preserve bit pattern | None | Zero extend |
unsigned long long | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | Preserve low-order bytes | None |
float | Convert to int, and convert int to unsigned char | Convert to unsigned int, and convert unsigned int to unsigned short | Truncate; if result is negative or too large, the result is undefined | Truncate; if result is negative or too large, the result is undefined | Truncate; if result is negative or too large, the result is undefined |
double | Convert to int, and convert int to unsigned char | Convert to unsigned int, and convert unsigned int to unsigned short | Truncate; if result is negative or too large, the result is undefined | Truncate; if result is negative or too large, the result is undefined | Truncate; if result is negative or too large, the result is undefined |
long double | Convert to int, and convert int to unsigned char | Convert to unsigned int, and convert unsigned int to unsigned short | Truncate; if result is negative or too large, the result is undefined | Truncate; if result is negative or too large, the result is undefined | Truncate; if result is negative or too large, the result is undefined |
Type Conversions--Floating-point Types | |||
To: |
float | double | long double |
---|---|---|---|
From: |
|||
signed char | Sign extend to int, and convert int to float | Sign extend to int, and convert int to double | Sign extend to int, and convert int to long double |
signed short | Sign extend to int, and convert int to float | Sign extend to int, and convert int to double | Sign extend to int, and convert int to long double |
signed int | Represent as float; if the int cannot be represented exactly, some loss of precision may occur | Represent as double; if the int cannot be represented exactly, some loss of precision may occur | Represent as long double; if the int cannot be represented exactly, some loss of precision may occur |
signed long | Represent as float; if the long cannot be represented exactly, some loss of precision may occur | Represent as double; if the long cannot be represented exactly, some loss of precision may occur | Represent as long double; if the long cannot be represented exactly, some loss of precision may occur |
signed long long | Represent as float; if the long long cannot be represented exactly, some loss of precision may occur | Represent as double; if the long long cannot be represented exactly, some loss of precision may occur | Represent as long double; if the long long cannot be represented exactly, some loss of precision may occur |
unsigned char | Sign extend to int, and convert int to float | Sign extend to int, and convert int to double | Sign extend to int, and convert int to long double |
unsigned short | Sign extend to int, and convert int to float | Sign extend to int, and convert int to double | Sign extend to int, and convert int to long double |
unsigned int | Represent as float; if the int cannot be represented exactly, some loss of precision may occur | Represent as double; if the int cannot be represented exactly, some loss of precision may occur | Represent as long double; if the int cannot be represented exactly, some loss of precision may occur |
unsigned long | Represent as float; if the long cannot be represented exactly, some loss of precision may occur | Represent as double; if the long cannot be represented exactly, some loss of precision may occur | Represent as long double; if the long cannot be represented exactly, some loss of precision may occur |
unsigned long long | Represent as float; if the long long cannot be represented exactly, some loss of precision may occur | Represent as double; if the long long cannot be represented exactly, some loss of precision may occur | Represent as long double; if the long long cannot be represented exactly, some loss of precision may occur |
float | None | Convert to double | Convert to long double |
double | Represent as float; if result is too large, result is undefined | None | Convert to long double |
long double | Convert to float | Represent as double; if result is too large to be represented as double, result is undefined | None |
Converting
Pascal String Literals
The -qmacpstr
option converts Pascal string literals of the form
"\pABC" into null-terminated strings where the first
byte contains the length of the string.
Integral
Promotion
The default compiler action is for integral promotions
to convert a char, short int, int
bitfield or their signed or unsigned types, or an
enumeration type to an int. Otherwise, the type
is converted to an unsigned int.
The -qupconv option promotes any unsigned type smaller than an int to an unsigned int instead of to an int.