Linux long long 和 long int 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7027150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between long long and long int
提问by Syedsma
I know the difference between long and int But What is the difference between "long long" and "long int"
我知道 long 和 int 之间的区别 但是“long long”和“long int”有什么区别
采纳答案by André Caron
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
.
short
是 (signed
)short int
long
是 (signed
)long int
long long
是 (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
在许多系统上,short
是 16 位、long
32 位和long long
64 位。但是,请记住,该标准仅要求
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.
其结果是,在外来系统上,这sizeof(long long) == 1
是可能的。
回答by Mark B
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
.
long long
可能是比 更大的类型long int
。例如,在 x86 上,32 位long long
将是 64 位类型,而不是 32 位long int
。
回答by richardolsson
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.
在int
16个系统是16位。A“ long
”被引入作为一个32位整数,但在32个系统long
和int
意思是相同的(都是32位)。所以在32位和64位的系统,long long
并且long int
都是64位。例外是 64 位 UNIX,其中long
64 位。
See the integer Wikipedia articlefor a more detailed table.
有关更详细的表格,请参阅整数维基百科文章。
回答by pmr
long int
is a synonym for long. long long int
is a synonym for long long
.
long int
是长的同义词。long long int
是 的同义词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.
在标准 C++ 中唯一的保证是它long long
至少与C++一样大,long
但可以更长。这在标准 n3242 的最新公开草案中的第 3.9.1.2 节中有详细说明。
回答by Kerrek SB
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.
除了类型需要能够表示的值的最小范围之外,C 标准没有对整数类型提出任何特定的宽度要求,并且宽度是非递减的:(short <= int <= long int <= long long int
对于无符号类型也是如此)。long long
顺便说一下,它只是在 C99 和 C++0x 中成为标准的一部分。可以在这篇 Wikipedia 文章中找到所需的最小范围。
回答by Nicola Musatti
According to the C
standard the integral types are defined to provide at least the following ranges:
根据C
标准,积分类型被定义为至少提供以下范围:
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.
每个都可以表示为支持更广泛的范围。在常见的 32 位系统上int
并long
具有相同的 32 位表示。
Note that negative bounds are symmetric to their positive counterparts to allow for sign and magnitude representations: the C language standard does notimpose two's complement.
请注意,负边界与其正对应项对称,以允许符号和幅度表示:C 语言标准不强加二进制补码。
回答by cs94njw
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.
“long”使分配给数据类型的位数加倍。这么长(32 位?)变成了 64 位。Int(16 位?)变成 32 位。
回答by Arun
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.
在 64 位系统上,它们的大小没有任何区别。在 32 位系统上 long long 保证存储 64 位范围的值。
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.
为了避免所有这些混淆,最好使用标准的整数类型:(u)int16_t, (u)int32_t and (u)int64_t
available viastdint.h
提供透明度。