By my reading of the C++ Standard, I have always understood that the sizes of the integral fundamental types in C++ were as follows:
sizeof(char) <= sizeof(short int) <= sizeof(int) <= sizeof(long int)
- There are four signed integer types: “signed char”, “short int”,
“int”, and “long int.” In this list,
each type provides at least as much
storage as those preceding it in the
list. Plain ints have the natural size
suggested by the architecture of the
- [...] large enough to store any member of the implementation’s basic character set.
- The fundamental storage unit in the C + + memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set and is composed of a contiguous sequence of bits, the number of which is implementation-defined.
1 == sizeof(char) <= sizeof(short int) <= sizeof(int) <= sizeof(long int)
long is guaranteed (at least) 32 bits.
LONG_MIN -2147483647 // -(2^31 - 1)
LONG_MAX +2147483647 // 2^31 - 1
The answer is definitively YES. Read my OP and all the comments to understand why exactly, but here's the short version. If you doubt or question any of this, I encourage you to read the entire thread and all of the comments. Otherwise accept this as true:
LONG_MINis defined as no greater than
LONG_MAXis defined as no less than
+2147483647in binary, you need 32 bits.
long must be at least 32 bits1.
LONG_MAX have values with magnitudes dictated by the C standard (ISO/IEC 9899:TC3) in section §18.104.22.168.1:
[...] Their implementation-defined values shall be equal or greater in magnitude [...] (absolute value) to those shown, with the same sign [...]
— minimum value for an object of type long int LONG_MIN -2147483647 // -(2 ^ 31 - 1) — maximum value for an object of type long int LONG_MAX +2147483647 // 2 ^ 31 - 1
1 32 bits: This does not mean that
sizeof (long) >= 4, because a byte is not necessarily 8 bits. According to the Standard, a byte is some unspecified (platform-defined) number of bits. While most readers will find this odd, there is real hardware on which
CHAR_BIT is 16 or 32.