On Sat, 24 Mar 2007 02:05:51 +0100, John Doe
<NOTOSPAMjohndoe64738@yahoo.comwrote in comp.lang.c++:
Quote:
Let's say I did this:
>
i -= u;
>
i is a signed int and u is an unsigned int. According to the c++
standard the rvalue result is going to be converted to unsigned int?
No, the rvalue result will not be converted at all. 'i', the signed
int, will be converted to unsigned int, then the subtraction will be
performed, naturally yielding an unsigned int result automatically.
The conversion is on the operand, not the result.
Quote:
Then what? Where does it say the result can be assigned to an int?
Where does it say that it cannot? The C++ standard defines integer
functions clearly. The unsigned int result of the subtraction is
automatically converted to signed int by the assignment. If the value
of the unsigned int result is within the range of values that can be
represented in signed int, that value will be stored in the signed
int. If the value of the unsigned int is greater than INT_MAX, then
the value stored in 'i' is implementation-defined.
Quote:
— Otherwise, if either operand is unsigned, the other shall be converted
to unsigned.
The line you are quoting above says that the other operand is
converted, not the result.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html