如何修复错误代码C4146“一元减号运算符应用于无符号type.result仍未签名”? [英] How can I fix error code C4146 "unary minus operator applied to unsigned type.result still unsigned"?
本文介绍了如何修复错误代码C4146“一元减号运算符应用于无符号type.result仍未签名”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据类型 int
的最小值是-2,147,483,648。
Data type int
's minimum value is -2,147,483,648.
所以,我输入了
int val = -2147483648;
但是,它有一个错误:
unary minus operator applied to unsigned type.result still unsigned
我该如何解决?
推荐答案
2147483648
超出 int
您平台上的范围。
2147483648
is out of int
range on your platform.
使用更精确的类型来表示常量
Either use a type with more precision to represent the constant
int val = -2147483648L;
// or
int val = -2147483648LL;
(取决于哪种类型的精度高于 int
在你的平台上。)
(depending on which type has more precision than int
on your platform).
或诉诸旧的 - 1
技巧
int val = -2147483647 - 1;
这篇关于如何修复错误代码C4146“一元减号运算符应用于无符号type.result仍未签名”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文