Pregunta

Este programa está escrito en VC ++ 6.0 en una máquina de WindowsXP.

Si intento configurar una variable __int64 a -2500000000 directamente, se trunca a un valor de 32 bits y se toma el complemento de los dos.

__int64 testval;
testval = -2500000000;

En este punto Testval es igual a 1794967293 (110 1010 1111 1101 0000 0111 0000 0000 binario).

Cuando configuré la variable a 2500000000 y luego multiplica por uno negativo, funciona:

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

La variable Testval es igual a -2500000000 (1001 0101 0000 0010 1111 1001 0000 0000 binario).

¿Alguna idea? Gracias.

¿Fue útil?

Solución

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!

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top