posted 24 years ago
Tom
Your second program compiles because you are supplying a compile-time literal value which fits in a byte, so no cast is needed. This is demonstrated by the following line which compiles ie. your line of code without the cast.
The important point is that -64>>4 can be calculated at compile time and returns -4 which is acceptable as a byte.
Your third program does not compile because the unsigned right-shift of -64 produces a very large value, far too big for a byte. So, even though the result of the shift is available at compile time, the compiler can see that you are trying to squeeze a large value into a byte, so it objects. You can make the code compile by bracketing the shift operation and applying the cast to it, but the result is truncated.
I think this explains what your are observing. There is no inconsistency.