tags:

views:

128

answers:

3

Hello,
I am a bit confused about old/new so that's my question. What is the biggest numerical primitive datatype in the old and in the new C++ standard? (integer and floatingpoint)

regards & many thanks in advance
Oops

+2  A: 

Have a look at

C and C++ Data Types

Data Type Ranges

Variables. Data Types. section Fundamental data types

astander
+4  A: 

In the 1998 standard, long int and unsigned long int are the types that are at least as big as any of the standard's other integral types (§3.9.1/2-3). (They may or may not be "the biggest" types. It's possible for long int to be the same size as int, for instance. For that matter, char could be the same size, too.) The floating-point long double provides at least as much precision as the other two floating-point types (§3.9.1/8).

In the draft standard for C++0x (n3092), the types are long long int and unsigned long long int (§3.9.1/2-3). The most precise floating-point type remains long double (§3.9.1/8).

Implementations may provide bigger types beyond what the standard calls for. Check the documentation for details on that.

Rob Kennedy
However, C++0x has `<stdint>`, so intmax_t and uintmax_t are the biggest integer types.
Steve Jessop
just for the record, the standard does specify minimum sizes, so a `long int` can never be the same size as a char. From memory, an `int` must be at least 16 bits wide, and a `long int` at least 32.
jalf
And in C++0x, even operations such as `sizeof` and things may yield types even bigger than `unsigned long long`, but not so on C++03.
Johannes Schaub - litb
@jalf: I think they're only bit minimums, so `char` could be the same size as `long` if CHAR_BIT was 32, for example.
GMan
@GMan: fair point. You're right
jalf
+1  A: 

In C++03, long [int] and unsigned long [int] have greatest integral range and long double has greatest FP precision and range.

In C++0x, intmax_t and uintmax_t have greatest integral range, and may even be bigger than long long. For example, it would be reasonable for an implementation to make both long and long long 64-bit and make intmax_t 128-bit.

intmax_t is merely being adopted from C99, so if your implementation supports C99, you don't need to require C++0x. Simply include stdint.h instead of cstdint. Use of "C-style" headers is perfectly safe anyway, although I'm not sure if there's a good way to check for C99 typedefs within C++.

Precisely or conveniently named floating point types were not introduced with C99 or C++0x, so do avoid anything like float64_t or floatmax_t if you want portability.

Potatoswatter
I still think that `intmax_t` should have been named `longest long int`.
James McNellis