svn commit: r286519 - head/contrib/binutils/gas/config

Bruce Evans brde at optusnet.com.au
Sun Aug 9 17:21:16 UTC 2015


On Sun, 9 Aug 2015, Warner Losh wrote:

> Since when is LEFT shifting a signed number undefined. It is RIGHT
> shifting that’s undefined…

Always.  It always shifts out the sign bit in the usual 2's complement
representation, so must be undefined in that case.  It is undefined by
definition in other representions where the sign bit could have been
anywhere before C99.  Left shifting of a positive value is undefined
if the shift moves a bit into or through the sign bit.

Strangely, right shifting is never undefined.  It is implementation-
defined.  Now the sign bit may or may not be preserved or take part
in the shift, but other bits are never shifted into the sign bit
except possibly in weird pre-C99 representations, so overflow doesn't
occur and the usual reason for undefined behaviour of an expression --
that the correct result is unrepresentable -- doesn't apply.

I remembered this backwards too.

Bruce


More information about the svn-src-all mailing list