[英]How can I fix error code C4146 “unary minus operator applied to unsigned type.result still unsigned”?
Data type int
's minimum value is -2,147,483,648. 数据类型
int
的最小值为-2,147,483,648。
So, I typed 所以,我输入了
int val = -2147483648;
But, it has an error: 但是,它有一个错误:
unary minus operator applied to unsigned type.result still unsigned
How can I fix it? 我该如何解决?
2147483648
is out of int
range on your platform. 2147483648
超出了您平台上的int
范围。
Either use a type with more precision to represent the constant 使用具有更高精度的类型来表示常量
int val = -2147483648L;
// or
int val = -2147483648LL;
(depending on which type has more precision than int
on your platform). (取决于哪种类型的精度比平台上的
int
更高)。
Or resort to the good old - 1
trick 或者诉诸好老
- 1
招
int val = -2147483647 - 1;
-2,147,483,648
is interpreted as negation of 2147483648
. -2,147,483,648
被解释为2147483648
否定。 2147483648
exceed maximum positive integer on your system and is considered as unsigned. 2147483648
超过系统上的最大正整数,并被视为无符号。
Instead, try 相反,试试吧
-2147483647 - 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.