gpt4 book ai didi

c - 为什么-32768 在下面的平台上有 signed long 类型?

转载 作者:行者123 更新时间:2023-12-05 09:30:00 26 4
gpt4 key购买 nike

Suppose that on a platform, the minimal signedvalue is −2^15 = −32768 and the maximum value is 2^15 −1 = 32767. The constant 32768 then doesn’t fit into signed and is thus signed long. As a consequence, the expression -32768 has type signed long. Thus the minimal value of the type signed on such a platform cannot be written as a literal constant.

From Modern C by Jens Gustedt.

很容易理解为什么 32768 是 signed long,但为什么 -32768 也是 signed long 而不是 signed,给定最小值 signed -32768 的值?

最佳答案

因为 -32768 是正字面量 32768(它不适合 16 位值,因此必须由下一个更大的类型表示),然后对其应用一元减号(这不会改变类型)。

如果你写,例如( ( - 32767 ) - 1 ),你得到了 int 类型的常量。

关于c - 为什么-32768 在下面的平台上有 signed long 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70054600/

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