[英]Long long is 8 bytes, meaning?
I've read the answers to the question of why sizeof(long long)
is 8 on most systems, but I'm still not sure how to interpret the meaning of them.我已经阅读了为什么
sizeof(long long)
在大多数系统上为 8 的问题的答案,但我仍然不确定如何解释它们的含义。
One of the reasons given is that there is a lot of code 'out there' which assumes that sizeof(long long) <= sizeof(size_t)
.给出的原因之一是“那里”有很多代码假设
sizeof(long long) <= sizeof(size_t)
。 That makes sense.这就说得通了。 Then there are all kinds of views on architecture conventions and brands, etc. I don't even want to get into those debates about the history of the convention.
然后还有关于建筑公约和品牌等各种观点,我什至不想参与那些关于公约历史的争论。 There are also reasons given that
long long
can be any size according to standard, but I think that is not really what concerns me.根据标准,
long long
可以是任意大小也是有原因的,但我认为这并不是我真正关心的问题。
What I want to know is how to interpret the difference now between the fact that sizeof(long long)
returns 8 but that a long long
actually is 16. Should it be interpreted as a historical remnant that applies only to the sizeof
operator, or is there an underlying address pointer associated with that fact, so that operations on a long long
are executed in 8 byte increments?我想知道的是,现在如何解释
sizeof(long long)
返回 8 而long long
实际上是 16 这一事实之间的差异。是否应该将其解释为仅适用于sizeof
运算符的历史残余,或者是是否有一个与该事实相关的底层地址指针,以便对long long
操作以 8 字节增量执行?
Sizeof (signed) long v4: 8 Value of (x at 2147483647)v4: 7fffffff Sizeof (signed) long v4: 8 (x at 2147483647)v4 的值:7fffffff
Sizeof long long v5: 8 Value of (x at 9223372036854775807)v5: 7fffffffffffffff sizeof long long v5:8 (x at 9223372036854775807)v5 的值:7ffffffffffffffff
According to the standard, long long
is at least 64 bits, or say, 8 bytes. 根据标准,
long long
至少为64位,即8个字节。
On most machines today, it is 8 bytes long. 在当今的大多数计算机上,它的长度为8个字节。
sizeof
(BTW, an operator, not a function) returns its size, you can count on it. sizeof
(顺便说一句,运算符,不是函数)返回其大小,您可以依靠它。 There's no way sizeof(long long)
is 8
while the size of long long
is 16
. sizeof(long long)
不可能是8
而long long
的大小是16
。
The longest standard data type is 8 bytes (64 bits) on most of the systems, Which is long long
. 在大多数系统上,最长的标准数据类型是8字节(64位),这是
long long
。
In addition you can include limits.h
which library contains defined values for each data type and the space it occupies on your system. 另外,您可以包括
limits.h
,该库包含每种数据类型的定义值以及它在系统上占用的空间。
A slight update during the fact I've encountered some level of interest over long
. 我
long
遇到了一定程度的兴趣期间略有更新。 It is guaranteed to be at least 32 bits (or 4 bytes) long. 保证至少32位(或4字节)长。 So as
long int
(though in that case, long
is rather a length modifier). 因此,
long int
(尽管在这种情况下, long
就是一个长度修饰符)。
问题是您的系统的一部分已切换到 64 位,而您的系统的一部分仍在以 32 位运行。
Somewhere there is a confusion and I am not sure where it is, because you don't say where you get your numbers from, so I will try to clarify the basics.某处存在混淆,我不确定它在哪里,因为你没有说你从哪里得到你的数字,所以我会尽量澄清基础知识。
sizeof
returns by definition the number of bytes a type occupies. sizeof
根据定义返回类型占用的字节数。 On all modern systems a byte is composed of 8 bits, but on some esoteric or old architectures a byte has other number of bits.在所有现代系统上,一个字节由 8 位组成,但在一些深奥或旧的体系结构中,一个字节具有其他数量的位。
CHAR_BIT
from limits.h
tells you how many bits there are in a byte. CHAR_BIT
从limits.h
告诉你有多少位有一个字节。 But again, on all modern architectures that's 8.但同样,在所有现代架构上,都是 8。
sizeof(long long) returns 8 but that a long long actually is 16.
sizeof(long long) 返回 8,但 long long 实际上是 16。
That is not true.那不是真的。 If
sizoef(long long)
is 8 then long long
is 8 bytes long.如果
sizoef(long long)
为 8,则long long
为 8 个字节长。
The follow-up question would be why sizeof(long) returns 8, but only holds 4bytes.
后续问题将是为什么 sizeof(long) 返回 8,但只包含 4 个字节。
Again, not true.再次,不是真的。 If
sizeof (long)
is 8
then long
holds 8 bytes.如果
sizeof (long)
为8
则long
包含 8 个字节。
The question turns out to be whether we ought to anticipate the elimination of the 4byte long, or not.
问题是我们是否应该预期消除 4 字节长。
Not a chance in hell.做梦都别想。 One of the pillars of C and C++ is backwards compatibility.
C 和 C++ 的支柱之一是向后兼容性。 Removing a fundamental type would break practically every program on the planet.
删除基本类型几乎会破坏地球上的所有程序。
If you ask if there is any use of the type long
when int
and long long
seem to cover everything then again the answer is int
and long long
don't cover everything.如果您问当
int
和long long
似乎涵盖所有内容时是否使用long
类型,那么答案又是int
和long long
并没有涵盖所有内容。 There are system like eg arduino where sizeof int == 2
, sizeof long == 4
and sizeof long long == 8
.有像 arduino 这样的系统,其中
sizeof int == 2
, sizeof long == 4
和sizeof long long == 8
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.