lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Tue, Mar 25, 2014 at 11:36 AM, Roberto Ierusalimschy
<> wrote:
> - Formally, even C99 does not have signed shifts:
>   ISO/IEC 9899:1999 (E)
>   6.5.7 Bitwise shift operators
>    4.The result of E1 >> E2 is E1 right-shifted E2 bit positions. [...]
>      If E1 has a signed type and a negative value, the resulting value is
>      implementation-defined.
> (I know that most implementations do signed shifts in that case, but its
> absence from the standard means something...)

Its absence from the standards meant that C's heritage as a thin
wrapper around machine language in the 70s is lurking in the name of
backwards compatibility. It means the standards committee wasn't
willing to standardize on something that different hardware
manufacturers disagreed on before I was born. There's a de-facto
standard in place now -- not only do all of the major C/C++
implementations use arithmetic (signed) shifts, it IS standardized for
every other language I've taken the time to look up: Java, C#,
Javascript, Python, and PHP all agree that right shifts are arithmetic

Having Lua disagree in this respect violates the principle of least surprise.

/s/ Adam