gpt4 book ai didi

c - 左移且移位计数为负

转载 作者:行者123 更新时间:2023-11-30 16:33:56 25 4
gpt4 key购买 nike

这里到底发生了什么?

a << -5

显然它没有右移。但我正在读的书指出:

On one machine, this expression actually does a left shift of 27 bits

我的问题是;为什么?左移 27 位的原因是什么?当移位计数为负时,到底会发生什么?谢谢。

最佳答案

右侧的负整数是 C 语言中未定义的行为。

ISO 9899:2011 6.5.7 按位移位运算符:

The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined.

关于c - 左移且移位计数为负,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49484940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com