I know, but the proposed solution is still worth considering as it gives
you the best of both worlds with just a little compile time overhead.
It yields the same result on 2s complement machines as the current function
but also on other machines because it is well defined.
This means that
clang++
Right now protobuf implementation assumes 2s complement and won't work on
any other environments. That's undefined behavior according to C++ standard
but in practice it's very unlikely to be a problem.
On Tue, Apr 25, 2017 at 5:42 AM, Wolfgang Brehm
wrote:
> right shifting negative integers is t
right shifting negative integers is tecnically undefined, this means that
the implementation used for encoding integers:
(n<<1)^(n>>(digits-1))
is tecnically undefined according to:
> The value of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits
> are zero-filled. If E1 has an unsigned