无法分配-2147483648到long long类型的变量 [英] Can't assign -2147483648 to variable of type long long
问题描述
我编译下面,由于某种原因,我不能指定-2147483648到这是8个字节长,并签署了变量code。
I'm compiling the code below and for some reason I can't assign -2147483648 to the variable which is 8 bytes long and signed.
long long x = -2147483648;
当我跨过这条线,x的值是2147483648和观察在微软的Visual Studio窗口显示x的类型为__int64。一个的sizeof(X)也将返回8。
When I step over this line, the value of x is 2147483648 and the 'Watch' window in MS Visual Studio shows that the type of x is __int64. A sizeof(x) also returns 8.
据limit.h的限制符号long long是:
According to limit.h the limits for a signed long long are:
#define LLONG_MAX 9223372036854775807i64 /* maximum signed long long int value */
#define LLONG_MIN (-9223372036854775807i64 - 1) /* minimum signed long long int value */
和
/* minimum signed 64 bit value */
#define _I64_MIN (-9223372036854775807i64 - 1)
/* maximum signed 64 bit value */
#define _I64_MAX 9223372036854775807i64
我只是不明白这一点!
I just don't get it!!!
有人请阐明这一些轻?
推荐答案
如果没有LL,编译器似乎演绎 2147483648
是一个32位的无符号长
。的然后的适用的 -
运营商。其结果是 0 - 2147483648
。由于这是小于0,作为一个无符号长T
, 4294967296
添加,这是 2147483648
一次。那么这个值被分配给久长X
。
Without the LL, the compiler appears to deduce 2147483648
is a 32-bit unsigned long
. Then it applies the -
operator. The result is 0 - 2147483648
. Since this is less than 0 and being an unsigned long t
, 4294967296
is added, which is 2147483648
again. This value is then assigned to long long x
.
建议:
long long x = -2147483648LL;
// or
long long x = -2147483647 - 1;
这篇关于无法分配-2147483648到long long类型的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!