P
Philip Lantz
Tim said:Actually there's a big difference. It may be rare that the
difference has a significant effect, but it can. Doing a left
shift of a negative value can easily produce a trap representation
(obviously only in implementations that have trap representations
for signed integers). This may not occur often, but certainly it
is not unheard of. So the 'undefined behavior' consequences are
not just imaginary. By contrast, a right shift of a negative
value must produce some valid value -- it can't just blow up the
way a left shift of negative values can.
Yes. All I meant by "no difference" was that neither one can be used in
portable code. (My impression is that most contributions to this
newsgroup focus on portable code, which is why I didn't feel the need to
clarify that. I suppose there might be some portable usage of a signed
right shift that can deal with the fact that the result may vary, but
that seems a bit unlikely.)