我需要 64 位处理器才能使用 64 位数据类型吗
我有几个问题:
我是否需要有 64 位处理器才能使用 64 位数据类型(__int64 或 int64_t)?
int64_t 的“t”是什么意思?
从什么版本的GCC和VCC开始支持数据类型?
64 位数据类型只是将数据长度加倍还是还有其他一些事情发生?
I have a few questions:
Do I need to have 64 bit Processor to use 64 bit data type(__int64 or int64_t) ?
What means by, the "t" of int64_t?
Starting from what version of GCC and VCC are supporting data type?
Is the 64 bit data type are just doubling the data length or there are some other things going under the hood too?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不需要 64 位处理器即可使用 64 位数据类型。这一切都取决于编译器,并且仅取决于编译器。如果需要,编译器可以为您提供 128 位、237 位或 803 位数据类型。
但是,请记住,通常 32 位 CPU 无法直接处理 64 位值,这意味着支持 64 位类型的所有必要语言操作的负担由编译器和库承担。编译器必须生成或多或少复杂的 32 位 CPU 指令序列,以便对 64 位值执行加法、移位、乘法等。这意味着在为 32 位 CPU 生成的代码中,对 64 位数据类型的基本语言操作将不如为 64 位 CPU 生成的代码高效(因为在后者中,大多数语言操作将由一条 CPU 指令)。
int64_t
中的“t”代表“type”或“typedef name”。这是标准库 typedef 的旧的公认命名约定。至于编译器版本,实际上是一个模棱两可的问题。 typedef 名称
int64_t
是 C 语言标准库的一部分(但不是 C++ 语言),而对 64 位整数类型(任何名称)的支持是编译器的一部分。那么你问的是哪一个呢?例如,MSVC编译器长期以来一直支持64位数据类型,但这些类型的名称一直不同。 64 位有符号整数在 MSVC 中被称为 __int64 。至于int64_t
typedef,据我所知,即使在今天,它也不是 MSVC 标准库的一部分。事实上,int64_t
从其规范的C99版本开始成为C语言的一部分。同时它不是C++语言的一部分。因此,一般来说,无论编译器的版本如何,您都不应该期望 C++ 代码中包含int64_t
。至于数据长度……嗯,是的,只是位数增加了一倍。其余的如下。
You don't need 64 bit processor to use 64 bit data type. It all depends on the compiler and only on the compiler. The compiler can provide you with 128-bit, 237-bit or 803-bit data types, if it so desires.
However, keep in mind that normally 32-bit CPUs cannot handle 64-bit values directly, which means that the burden of supporting all necessary language operations for 64-bit type lies on the compiler and the library. The compiler will have to generate a more-or-less complex sequence of 32-bit CPU instructions in order to perform additions, shifts, multiplications etc. on 64-bit values. This means that in code generated for 32-bit CPUs basic language operations on 64-bit data types will not be as efficient as they would be in code generated for 64-bit CPUs (since in the latter most language operations would be carried out by a single CPU instruction).
The "t" in
int64_t
stands for either "type" or "typedef name". That's an old accepted naming convention for standard library typedefs.As for compiler versions, it is an ambiguous question actually. The typedef name
int64_t
is a part of the standard library of C language (but not of C++ language), while the support for 64-bit integer types (under any name) is a part of the compiler. So which one are you asking about? For example, MSVC compiler has been supporting 64-bit data types for a long time, but the names for these types have been different. 64-bit signed integer is called__int64
of something like that in MSVC. As for theint64_t
typedef, AFAIK, it is not a part of MSVC's standard library even today. In fact,int64_t
became a part of C language from the C99 version of its specification. At the same time it is not a part of C++ language. So, generally, you are not supposed to expect to haveint64_t
in C++ code regardless of the version of the compiler.As for data length... Well, yeah, it is just doubling the number of bits. The rest follows.
如果您查看
/usr/include/stdint.h
,您会发现int64_t
被定义为因此,正如 David 所说,它是编译器而不是体系结构相关的。
If you look at
/usr/include/stdint.h
, you'll find thatint64_t
is defined asSo, as David said, it's compiler and not architecture dependent.
不,32 位架构上的编译器模拟 64 位算术。虽然速度不是特别快,但也没有那么糟糕。
t
指的是类型
。这是 C 语言的遗产,其中必须以不同方式引用结构。64 位整型可能会增加对齐方式,但仅此而已。
我不知道第3点。
No, compilers on 32bit architectures emulate 64bit arithmetic. It's not terribly fast, but it's not that bad.
The
t
refers totype
. This is legacy from C where structs would have to be referred to differently.64bit integral types may have increased alignment, but that's about it.
I've no idea for point 3.