Sign in to follow this  

__int64 vs long long [solved]

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know that __int64 can only be used on windows, but what about long long? They both make an int of 64 bits, but I'm not sure if there is any difference between the two. Is there? [Edited by - MikeTacular on May 22, 2006 1:56:27 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
I know that __int64 can only be used on windows, but what about long long? They both make an int of 64 bits, but I'm not sure if there is any difference between the two. Is there?


__int64 is not platform specific, it is compiler specific - just as long long. While long long is probably making his way into the next C++ standard, none of them are currently standard (both are extensions to the core language). Anyway, there is no real difference between the two: as you said, both are used to create a 64 bit integer... on today's 32 bit platforms. While __int64 is probably guaranteed to always implement 64 bit integers (due to its name), long long is not tied to a particular bit size. It just happen to be 64 bit long on most 32 bit platforms.

I have to recall you what the standard says about the size of different data types: sizeof(char) = 1 byte (the number of bits in the byte is not defined by the standard); then

sizeof(long) >= sizeof(int) >= sizeof(short) >= sizeof(char)

The next standard will probably introduce

sizeof(long long) >= sizeof(long)

The standard don't say anything more, meaning than if sizeof(char) is 8 bits you can build a perfectly compliant compiler where the size of all the other integral type is also 8 bits, the main point beeing that sizeof(int) is not quaranteed to be 32 bits. Which in turn says that when long long will be standardized (if it is), its size will not be guaranteed to be 64 bits.

HTH,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
The standard don't say anything more, meaning than if sizeof(char) is 8 bits you can build a perfectly compliant compiler where the size of all the other integral type is also 8 bits ...

Actually, I don't think that's exactly true.
I was under the impression that the standard defines certain ranges of values that the types must be able to store, which lead to some guarantees that, eg, the size of the int type must be at least 16 bits. Of course, continuing the same example, sizeof(int) may still be equal to sizeof(char), if the char type is also 16 bits.

John B

Share this post


Link to post
Share on other sites
It depends on what standard you're talking about. I believe C99 specifies minimum sizes but older versions don't necessarily. Note that MSVC is not C99 compliant.

If you are using a C99 compiler there are already typedefs for you, e.g. int32_t. Is int64_t standard?

Share this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
It depends on what standard you're talking about. I believe C99 specifies minimum sizes but older versions don't necessarily. Note that MSVC is not C99 compliant.

If you are using a C99 compiler there are already typedefs for you, e.g. int32_t. Is int64_t standard?

Ah, that may well explain it.

John B

Share this post


Link to post
Share on other sites

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this