Skip to main content
GameDev.net gamedev.net
🔒 Locked

64 bit integer types

Started by Halma Sep 26, 2005 at 3:22 PM 6 replies 1.6k views
Original Post
Halma
Halma
Hello, I was wondering what type I'd have to use to get a 64 bit integer. With GCC, "long long int" works. But I don't think that works in Visual C++. Is there a standard way? I remember spending a few hours with 2 other people a few years ago trying to figure out how to get 64 bit integers with Visual C++ 6. It turned out that the type we were using, I think it was __int64, didn't support comparison! So what on earth can we do with an integer if we can't compare it? Do .NET 2002 or .NET 2003 have a 64 bit integer that works? I've seen the LARGE_INTEGER in windows.h, is that usable?
dyerseve
dyerseve
that was me
bakery2k1
bakery2k1
__int64 is what you want. LARGE_INTEGER is probably the one that doesn't support comparisons, since it is a union: msdn.
gregs
gregs
I have just tried the following code on VS6 and VS.NET2k3, and it worked fine on both.

#include <cstdio>int main(){	__int64 val1=7654321,val2=1234567;	printf("Equals: %s \n",val1==val2 ? "true" : "false" );	printf("Less than: %s \n",val1<val2 ? "true" : "false" );	printf("More than: %s \n",val1>val2 ? "true" : "false" );	return 0;}
zoggo
zoggo
I am hardly an authority on this but my readings suggest this is the current position:

"long long int" is a gcc extensions to C++ and a standard part of C99. VC7.1 (Dunno about prior to this) supports this syntax as an extension.

VC7.1 also supports sized types using the __int## syntax. Thus __int64 works and is usable pretty much as any other primitive type.

Both the above support all normal arithmetic ops including comparison. I can't speak for VC6 because it has been a long time since I have used that heap of crap.

LARGE_INTEGER is a struct representing a 64 bit int made from two 32 bit types. You have to use special windows api function to manipulate them.

To add to the confusion on 64 bit systems the "long int" family of types have mostly become 64 bits.

The C++ standard is particularly unhelpfull on the subject. It basically says:

sizeof( char ) == 1
sizeof( char ) <= sizeof( short int ) <= sizeof( int ) <= sizeof( long int )

It suggests that unadorned int should be the machine word size but even this ceases to be true on most current 64 bit implementations where sizeof( int ) remains 4.

This is why the commitee is considering making stdint.h (presumably as cstdint) available in standard C++ as it is in C99.
Halma
Halma
Thanks guys, for clearing that up.. Apparently they fixed the __int64.

I remember seeing in the MSDN documentation for Visual C++ 6, that __int64 didn't support comparison properly. In any case, we had a lot of really weird problems using it in VC6. For example, we had something like this:

void callfunction(__int64 var) {   if (var==453) cout<<"Equal"<<endl;}int main() {   __int64 test;   test = 453;   callfunction(test);   return 0;}


And it wouldn't write equal.. The value of the variables would change when we called functions! It was really crazy. I'm glad they fixed it.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.