quinta-feira, maio 21, 2009

How to declare 64 bits in Visual Studio 6

Did you ever needed to declare a 64 bits integer using Visual Studio 6?

On newer versions of Visual Studio and on gcc you can use the ll to tell the compiler that the value is 64 bits wide. But Visual Studio 6 does not understand it.

How do you do? You must use the keyword

I discovered it because a project I wrote using Visual Studio 2005 that must be compiled using Visual Studio 6.

Below you can see a sample code that compiles both in VS 6 and 2005.

#include "stdafx.h"

int main(int argc, char* argv[])
__int64 i = 0;

printf("Hello World! %08x %08x\n", i);

#ifdef _MSC_VER
#if _MSC_VER <= 1200
// Visual Studio 6 or lower do not accept ll as 64 bits constants.
#endif // _MSC_VER
#endif // _MSC_VER

i = ((__int64)0x1234567890123456);
i = 0x1234567890123456ll;

printf("Hello World! %08x %08x\n", i);
return 0;
I really hope this piece of information will be helpful to someone.

Nenhum comentário: