Suppose that on a platform, the minimal signed value is −2^15 = −32768 and the maximum value is 2^15 −1 = 32767. The constant 32768 then doesn’t fit into
signed
and is thussigned long
. As a consequence, the expression -32768 has typesigned long
. Thus the minimal value of the typesigned
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 类型的常量。
https://stackoverflow.com/questions/70054600/