tags:

views:

530

answers:

6

Which is the biggest integer datatype in c++?

A: 

In the Borland and Microsoft compilers, __int64 is probably the largest you can get.

David Andres
+4  A: 

The long long data-type is the largest built-in integral datatypes in standard C99 and C++0x. Just as with all of the other integral data types, long long is not given an exact size in bytes. Instead, it is defined to be at least a 64-bit integer. While long long is not part of the official C++ standard, it is ubiquitously supported across modern compilers. Note, however, that many compilers for modern desktops define long and long long as both exactly 64-bits, whereas many compilers for embedded processors define long as 32-bits and long long as 64-bits (obviously witha few exceptions).

If you need more precision or absolutely cannot use the long long language extension, you're going to have to use one of the C or C++ libraries that are designed to work with extremely large or small numbers.

Mike Koval
"...as long long and long will both be 64-bits on most modern desktop CPUs." Not true. Depends on the compiler. In LLP64 model (which is used by VC), `long` remains 32-bit and `long long` is 64-bit.
Mehrdad Afshari
See this link http://en.wikipedia.org/wiki/LLP64#Specific_data_models for the possible 64 bit memory models.
Andy J Buchanan
FYI, `long long` is not in the C++ standard. It's added to C in C99. Currently, it's a ubiquitous extension supported by most compilers.
Mehrdad Afshari
long long is part of C++0x (or should I say C++1x, now?), see http://www.research.att.com/~bs/C++0xFAQ.html#long-long
stephan
Please advise where in the standard it says long longs are at least 64 bits. The only part of the standard I've seen that mentions this states that each of the integral types is at least as big as the next smaller one. That means a conforming implementation can give 8bits for char, int, long and long long.
paxdiablo
Pax, <climits> defines macros INT_MAX et al. The standard defines minimal values for these, effectively establishing minimum number of bits required for the representation of the built-in integral types. It's 16 for int, 32 for long and (int the new standard) 64 for long long.
avakar
Where in the standard does it say that `long long` **exists**? *It does not even exist in C++ yet*. It is a C datatype, and yes, it will be added in C++0x, but at the moment, it does not exist in C++. -1
jalf
Jalf, is there a C++ compiler that does not support long long?
Crashworks
Sure there is, Comeau in strict mode. :)
avakar
@Crashworks: The question was "What is the biggest integer datatype in C++". It was *not* "What is the biggest datatype accepted by this or that compiler". I think most compilers will disallow it if you compile in strict mode, not just Comeau.
jalf
Also note that C99 and C++0x support/will support extended integer types. So it can happen that `size_t` is bigger than unsigned long long.
Johannes Schaub - litb
Anyway i'm sorry you get a -1. You may aswell say "the biggest datatype is `long long long long` in c++.", which aswell isn't supported by it either :)
Johannes Schaub - litb
+1  A: 

See this link Integer Limits C++ bye.

RRUZ
A: 

You can easily get bigger datatype by defining your own Class. You can get inspired from the class BigInteger in Java. It's a nice one but it's not necessarily an actual integer even if it acts exactly like one.

Omar Dolaimy
+3  A: 

There are 128 bit packed integer and floating point formats defined in xmmintrin.h on compilers that support SSE to enable use of the SSE registers and instructions. They are not part of the C++ standard of course, but since they are supported by MSVC, GCC and the Intel C++ Compiler there is a degree of cross-platform support (at least OS X, Linux and Windows for Intel CPUs). Other ISAs have SIMD extensions so there are probably other platform/compiler specific extensions that support 128 or 256 bit SIMD instructions. Intel's upcoming AVX instruction set will have 256 bit registers, so we should see a new set of data types and intrinsics for that.

They don't behave quite like built-in data types (i.e., you have to use intrinsic functions instead of operators to manipulate them, and they work with SIMD operations) but since they do in fact map to 128-bit registers on the hardware they deserve mention.

Details about Streaming SIMD Extension (SSE)Intrinsics

Whatever
+14  A: 

The biggest standard C++ integer type is long.

C has a long long, and C++0x is going to add that as well, and of course you could implement your own custom integer type, perhaps even a BigInt class.

But technically speaking, considering the built-in integer types, long is your answer.

jalf
Technically, the next C++ standard may not have the long long type. There is nothing that can't be pulled from the standard even at this late stage. But +1 for being a (correct) pedant :-)
paxdiablo
and you called *me* a pedant. ;) But yeah, fair point. At the moment, it looks like it's going to get included in C++0x, but who knows. :)
jalf