38

It says on wikipedia and in Stroustrup's FAQ that type long long is at least as long as an int and has no fewer than 64 bits. I have been looking at the C++11 standard §3.9.1 Fundamental Types section and I cannot find any reference to 64 bits. All I can find is that it is at least as long at long int, which is at least as long as int. The standard lists long long as a standard integer type, as opposed to an extended one, so I am wondering whether this assertion that long long holds at least 64 bits is true. And if it is, where is it stated?
Please note that I am talking about C++11 standard long long only.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • 3
    The standard, of course, is right. It just tells you what are the differences in size between the various types, like short, int, long, long long. The actual size, ie it is 64 bits or not, is platform dependent. As C++ compilers are available fro all sorts of platforms. You cn find the actual size specific to the platform, compiler, in specific header files. – ervinbosenbacher Apr 07 '12 at 09:01
  • 3
    @ErvinBosenbacher: the standard also specifies *minimum* sizes for the built-in types. The exact type is implementation-defined, yes, but an implementation can't just make up numbers – jalf Apr 07 '12 at 09:04
  • @jalf: Thanks, yes that is right :) Limits.h is the file. – ervinbosenbacher Apr 07 '12 at 09:09
  • 1
    @ErvinBosenbacher the references I quoted make explicit mention of 64 bits regardless of platform, which seems odd and is why I am asking the question. – juanchopanza Apr 07 '12 at 09:57

1 Answers1

38

The C++ standard references the C standard for this, see [c.limits]. LLONG_MAX is defined in <climits> with the same meaning as C's <limits.h>'s LLONG_MAX. And this is what C has to say:

5.2.4.2.1 Sizes of integer types <limits.h>

The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. [...] Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.

[...]

-- maximum value for an object of type long long int

LLONG_MAX +9223372036854775807 // 263 -1

A signed type that must be capable of representing the value 9223372036854775807 requires 64 bits or more.

Community
  • 1
  • 1
  • 1
    Thanks! I not very familiar with C99. Does the standard define what happens on, say, a 32 or 16 bit plaform? – juanchopanza Apr 07 '12 at 10:05
  • 12
    @juanchopanza It does so by not doing so: `long long` support is not optional, so if the hardware is not capable of performing 64-bit operations natively, it must emulate them somehow. It's the same as `long` support on a 16-bit platform. –  Apr 07 '12 at 10:23
  • @herohuyongtao I appreciate the edit, and made a few more tweaks to keep it as close to the formatting used in the standard as reasonable. –  Oct 11 '14 at 15:28