
long int type
Hi every body!
I hope you guys are having a good day.
I was reading about long int type in c++. Here is what i find:
A signed long can hold all the values between LONG_MIN and LONG_MAX inclusive. LONG_MIN is required to be 2147483647 or less,A signed long can hold all the values between LONG_MIN and LONG_MAX inclusive. LONG_MIN is required to be 2147483647 or less, LONG_MAX must be at least 2147483647. Again, many 2's complement implementations will define LONG_MIN to be 2147483648 but this is not required.
An unsigned long can hold all the values between 0 and ULONG_MAX inclusive. ULONG_MAX must be at least 4294967295. The long types must contain at least 32 bits to hold the required range of values. LONG_MIN to be 2147483648 but this is not required.
An unsigned long can hold all the values between 0 and ULONG_MAX inclusive. ULONG_MAX must be at least 4294967295. The long types must contain at least 32 bits to hold the required range of values.
================================================== ===
"long  min is required to be 21478364 or less",
my question is how much less? why long_min is required to be 214783647?
"A LONG_MAX must be at least 2147483647." why longmax must be atleast 2147483647?
Thanks a lot and have a nice day!

The point of the standard is to guarantee something. You know, no matter where you go (assuming a standardcompliant implementation) that a long int can handle that range. Some machines may give you a larger range, and a larger range would require a smaller number than 2147483648. The numbers were chosen as the range from LONG_MIN to LONG_MAX is a power of 2, specifically 2^32.

2147483647 or less, not 214748364.
How much less? How about 9223372034707292161 less? That's a real result, taken from GCC running on a 64bit Linux. There's no limit, really.
Why 2147483647? Because that's (2^31  1), which is the smallest value a signed 32bit value can take in a one's complement or sign/magnitude negative representation. The standard thus enforces this:
1) long (which is a synonym for long int) must be at least 32 bits wide (but may be wider).
2) One's complement and sign/magnitude are valid negative representations. So is two's complement, the most common representation these days.
And that large value I wrote above? That's the difference between (2^63) (the lowest value a two's complement 64bit integer can take) and (2^311).

Those values imply that you are dealing with a number that is AT LEAST 32 bits. If we have a 36bit processor, we can make long a 36bit number. On a 64bit machine that also supports 32bit numbers, it can use EITHER 32 or 64bit numbers  the spec allows the choice to be made by the implementation. In fact, in x8664 for Linux, a long is 64bit, and in x8664 running Windows, long is 32bit.

Mats

Thanks a lot guys for awesome responses!
have a nice day!