posted 23 years ago
I ran the three statements and they compile and run fine.
According to R & H, the reason that they compile is that the right hand value is implicitly downcasted to the appropiate type before assignment. R & H says this only works for integral types (char, byte, short, int) and that it only works if it is just an assignment not an expression. (page 65, 2nd ed.).
For example:
<pre>
byte x = 2; // Legal implicitly casts 2 to byte
byte x = (char)2; // same thing
x += (char)5; // Legal x now equals 7
x = x + (char)5; // Illegal, the right hand
// operands are promoted to
// int before being added
// and assigned. Requires
// explicit cast to byte
</pre>
Sorry if this was confusing, but check out page 65 in the R & H book for details. (prob different page in an older addition, it is the section on assignment Operators in he Operators and Assignments chapter).
[This message has been edited by scott nichols (edited March 31, 2001).]