-1

I vaguely remember reading a section in the C++ standard that stated the minimum width requirements for integer types. I cannot find this any more. The closest I can find is the description of <limits.h> in the C standard.

Where would I find the minimum widths of integer types?

ecatmur
  • 152,476
  • 27
  • 293
  • 366
Graznarak
  • 3,626
  • 4
  • 28
  • 47
  • If you're actually looking to use the size of these types in your code, I'd suggest using the exact sized types in stdint or in Boost.Integer. They are able to make cross platform guarantees about the sizes of the types they represent. If you just want to know for the sake of knowing, it varies by compiler. – KitsuneYMG Sep 16 '13 at 16:57
  • 1
    [This answer](http://stackoverflow.com/a/4337544/902497) to [Is \`long\` guaranteed to be at least 32 bits?](http://stackoverflow.com/questions/4329777/is-long-guaranteed-to-be-at-least-32-bits) gives the minimum required ranges for integer types. For `int`, the minimum range is `-32767` to `+32767` (5.2.4.2.1). – Raymond Chen Sep 16 '13 at 17:05

1 Answers1

2

The minimum range requirements defined in standard are (3.9.1 - Fundamental Types):

Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set.

and

There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”. In this list, each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types. Plain ints have the natural size suggested by the architecture of the execution environment44; the other signed integer types are provided to meet special needs.

Footnote 44 on this page says:

44) that is, large enough to contain any value in the range of INT_MIN and INT_MAX, as defined in the header <climits>.

And C standard in 5.2.4.2.1 says:

// minimum value for an object of type int
INT_MIN -32767 // −(215 − 1)
// — maximum value for an object of type int
INT_MAX +32767 // 215 − 1
Nemanja Boric
  • 21,627
  • 6
  • 67
  • 91
  • No, those are not the only guarantees. There are minimum range requirements (which imply minimum size requirements) for each type. – Benjamin Lindley Sep 16 '13 at 16:54
  • Where are the range requirements documented? – Graznarak Sep 16 '13 at 16:55
  • @Graznarak 3.9.1 - Fundamental types – Nemanja Boric Sep 16 '13 at 16:55
  • 1
    @Graznarak: The specific minimum range requirements do not exist in the C++ standard. They are little more than a footnote reference to the `` header and the C99 standard, which seems to imply a suggested range, not a hard requirement. – greyfade Sep 16 '13 at 17:04
  • @NemanjaBoric 3.9.1 only specifies relative sizes. I want to know where the minimum sizes for each integer type are specified. – Graznarak Sep 16 '13 at 17:04
  • 1
    @greyfade: The document says *"Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown ..."* -- I don't see how that can be read as not being a requirement. – Benjamin Lindley Sep 16 '13 at 17:09
  • @BenjaminLindley: The "soft requirement" I'm talking about is the contents of `limits.h`, since it's a loose reference to the C99 standard. – greyfade Sep 16 '13 at 17:12