On Sat, 1 Jun 2024 12:48:07 -0700 (PDT)
Jeremy Drake <wrote:
> On Sat, 1 Jun 2024, Takashi Yano wrote:
> 
> > +  const int destroyed = INT_MIN >> 1;      /* 0b1100000000000000 */
> 
> I thought whether or not right shifting a negative number sign-extends was
> undefined in the C/C++ standards?

It seems that it's implementation-defined till C++17 and arithmetic
shift since C++20.

gcc defines:
        "Signed ‘>>’ acts on negative numbers by sign extension."

Therefore, this works as intended. However, relying on implementation-defined
behavior may not be certainly a good idea.

-- 
Takashi Yano <takashi.y...@nifty.ne.jp>

Reply via email to