gpt4 book ai didi

c - 负移位计数左移

转载 作者:太空狗 更新时间:2023-10-29 16:17:05 26 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/4945703/

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