Is left and right shifting negative integers defined behavior?

后端 未结 3 2016
故里飘歌
故里飘歌 2020-11-27 18:24

I know, right shifting a negative signed type depends on the implementation, but what if I perform a left shift? For example:

int i = -1;
i << 1;
         


        
3条回答
  •  無奈伤痛
    2020-11-27 19:14

    otherwise, the behavior is undefined.

    This includes the

    if E1 has a signed type and non-negative value

提交回复
热议问题