pa********@hotmail.com wrote:
Re: What is the need for long when int and long are both 4 bytes
Where did you get that idea? Neither are required to be 4 bytes, and they
are not required to span the same range. The requirements are:
int can represent all integers in the interval [INT_MIN, INT_MAX].
long can represent all integers in the interval [LONG_MIN, LONG_MAX].
Moreover, we have the following guarantees inherited from C:
INT_MIN <= -32767
INT_MAX >= 32767
LONG_MIN <= -2147483647
LONG_MAX >= 2147483647
hi All
I understand the need for long long , but what is the purpose of long
as a data type separately. Just makes the language intimidating to
start with, when you have to deal with so many data types.
The requirements for the type int are somewhat special. If you look at
short, long, long long, you will find that they more or less match your
expectations. However, the idea behind int is that it should be
the "natural" arithmetic type of the machine (i.e., it should be
represented by one word). Now, what that means is a little iffy, e.g., do
you think of processor registers or of memory and bus architecture; but
that was the idea: in the word of the standard [3.9.1/2]:
... Plain ints have the natural size suggested by the architecture of the
execution environment [39]; the other signed integer types are provided to
meet special needs.
[39]= that is, large enough to contain any value in the range of INT_MIN
and INT_MAX, as defined in the header <climits>.
Best
Kai-Uwe Bux