I know the difference between long and int But What is th开发者_运维百科e difference between "long long" and "long int"
There are several shorthands for built-in types.
short
is (signed
)short int
long
is (signed
)long int
long long
is (signed
)long long int
.
On many systems, short
is 16-bit, long
is 32-bit and long long
is 64-bit. However, keep in mind that the standard only requires
sizeof(char) == 1
sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
And a consequence of this is that on an exotic system, sizeof(long long) == 1
is possible.
According to the C
standard the integral types are defined to provide at least the following ranges:
int -32767 to +32767 representable in 16 bits
long -2147483647 to +2147483647 representable in 32 bits
long long -9223372036854775807 to +9223372036854775807 representable in 64 bits
Each can be represented as to support a wider range. On common 32 bit systems int
and long
have the same 32 bit representation.
Note that negative bounds are symmetric to their positive counterparts to allow for sign and magnitude representations: the C language standard does not impose two's complement.
long long
may be a bigger type than long int
. For example on x86 32 bit long long
would be a 64-bit type rather than 32 bit for long int
.
On 64 bit systems it doesn't make any difference in their sizes. On 32 bit systems long long is guaranteed store values of 64 bit range.
Just to avoid all these confusions, it is always better to use the standard integral types: (u)int16_t, (u)int32_t and (u)int64_t
available via stdint.h
which provides transparency.
An int
on 16 bit systems was 16 bits. A "long
" was introduced as a 32 bit integer, but on 32 bit systems long
and int
mean the same thing (both are 32 bit.) So on 32 and 64 bit systems, long long
and long int
are both 64 bit. The exception is 64 bit UNIX where long
is 64 bits.
See the integer Wikipedia article for a more detailed table.
long int
is a synonym for long. long long int
is a synonym for long long
.
The only guarantee you have in standard C++ is that long long
is at least as large as long
but can be longer. This is specified in §3.9.1.2 in the most recent publicly available draft of the standard n3242.
The C standard doesn't make any specific width requirements for integral types other than minimal ranges of values that the type needs to be able to represent, and that the widths are non-decreasing: short <= int <= long int <= long long int
(similarly for the unsigned types). long long
only became part of the standard in C99 and C++0x, by the way. The minimum required ranges can be found in this Wikipedia article.
I think:
"long" doubles the number of bits allocated to the data type. So long (32 bits?) becomes 64 bits. Int (16 bits?) becomes 32 bits.
精彩评论