< previous page page_548 next page >

Page 548
someInt <= someFloat
The value of someInt is temporarily coerced to floating point representation before the comparison takes place. The only difference between arithmetic expressions and relational expressions is that the resulting type of a relational expression is always intthe value 1 (true) or 0 (false).
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Promotion (Widening) The conversion of a value from a lower type to a higher type according to a programming language's precedence of data types.
Here is a table that describes the result of promoting a value from one simple type to another in C++:
From
To
Result of Promotion
double
long double
Same value, occupying more memory space
float
double
Same value, occupying more memory space
Integral type
Floating point type
Floating point equivalent of the integer value; fractional part is zero
Integral typeIts unsigned counterpartSame value, if original number is nonnegative; a radically different positive number, if original number is negative
Signed integral type
Longer signed integral type
Same value, occupying more memory space
unsigned integral type
Longer integral type (either signed or unsigned)
Same nonnegative value, occupying more memory space
NOTE: The result of promoting a char to an int is compiler-dependent. Some compilers treat char as unsigned char, so promotion always yields a nonnegative integer. With other compilers, char means signed char, so promotion of a negative value yields a negative integer.

The note at the bottom of the table suggests a potential problem if you are trying to write a portable C++ program. If you use the char type only to store

 
< previous page page_548 next page >