此程序是在WindowsXP计算机上的VC ++ 6.0中写入的。

如果我尝试将__int64变量直接设置为-25000000,它被截断到32位值,并且拍摄了两个的补充。

__int64 testval;
testval = -2500000000;
. 在此目的中,TETVAL等于1794967293(1101010 1111 1101 0000 0111 00000000二进制)。

当我将变量设置为2500000000然后乘以负数时,它有效:

__int64 testval;
testval = 2500000000;
testval *= -1;
.

变量testval等于-2500000000(1001 0101 0000 0010 1111 1001 0000 0000二进制)。

任何想法? 谢谢。

有帮助吗?

解决方案

Get a newer compiler. VC6 standard compliance is VERY poor.

In VC6, try a suffix of i64, as in

__int64 toobig = -2500000000i64;

Found the documentation!

其他提示

The compiler is treating the constant 2500000000 as a 32-bit number. You need to explicitly tell it to treat it as a long int by appending an LL to the end of the constant. So, try instead:

testval = -2500000000LL;

Update: Since your compiler doesn't support this, and you are stuck with VC6, try instead breaking it into a value that results from the product of two 32 bit numbers as in:

testval = -250000;
testval *= 10000;

The correct syntax is -2500000000LL. If it doesn't work, get a newer compiler.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top