From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Andres Freund <andres(at)anarazel(dot)de> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: "left shift of negative value" warnings |
Date: | 2017-04-10 19:25:57 |
Message-ID: | 970.1491852357@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Andres Freund <andres(at)anarazel(dot)de> writes:
> On 2017-04-09 19:20:27 -0400, Tom Lane wrote:
>> As I read that, it's only "undefined" if overflow would occur (ie
>> the sign bit would change). Your compiler is being a useless annoying
>> nanny, but that seems to be the in thing for compiler authors these
>> days.
> "The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with
> zeros. If E1 has an unsigned type, the value of the result is E1 × 2 E2 , reduced modulo
> one more than the maximum value representable in the result type. If E1 has a signed
> type and nonnegative value, and E1 × 2 E2 is representable in the result type, then that is
> the resulting value; otherwise, the behavior is undefined."
> As I read this it's defined iff E1 is signed, nonnegative *and* the the
> result of the shift is representable in the relevant type. That seems,
> uh, a bit restrictive, but that seems to be the only reading?
Oh --- I misread the "nonnegative" as applying to the shift count, but
you're right, it's talking about the LHS. That's weird --- the E1 × 2^E2
definition works fine as long as there's no overflow, so why didn't they
define it like that? It seems just arbitrarily broken this way.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2017-04-10 19:41:10 | Re: Letting the client choose the protocol to use during a SASL exchange |
Previous Message | Andres Freund | 2017-04-10 19:16:54 | Re: "left shift of negative value" warnings |