我需要 64 位处理器才能使用 64 位数据类型吗

发布于 2024-10-29 22:54:59 字数 215 浏览 4 评论 0原文

我有几个问题:

  1. 我是否需要有 64 位处理器才能使用 64 位数据类型(__int64 或 int64_t)?

  2. int64_t 的“t”是什么意思?

  3. 从什么版本的GCC和VCC开始支持数据类型?

  4. 64 位数据类型只是将数据长度加倍还是还有其他一些事情发生?

I have a few questions:

  1. Do I need to have 64 bit Processor to use 64 bit data type(__int64 or int64_t) ?

  2. What means by, the "t" of int64_t?

  3. Starting from what version of GCC and VCC are supporting data type?

  4. Is the 64 bit data type are just doubling the data length or there are some other things going under the hood too?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

樱娆 2024-11-05 22:54:59

您不需要 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 the int64_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 have int64_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.

扶醉桌前 2024-11-05 22:54:59
  1. 不,您可以在 32 位机器上处理此类数据。只要您的编译器支持这些数据类型就可以。
  2. int64_t 只是它的名称,如标准中所定义。
  3. 我认为本世纪所有版本的 GCC 和 MSVC 都支持 32 位架构上的 64 位整数。
  4. 64 位整数的大小仅为 32 位整数的两倍。
  1. No, you can process such data on a 32 bit machine. So long as your compiler supports those data types you are fine.
  2. int64_t is just its name, as defined in the standard.
  3. I think all versions of GCC and MSVC this century support 64 bit integers on 32 bit architecture.
  4. A 64 bit integer is just twice the size of a 32 bit integer.
心碎无痕… 2024-11-05 22:54:59

如果您查看 /usr/include/stdint.h,您会发现 int64_t 被定义为

typedef long long int int64_t;

因此,正如 David 所说,它是编译器而不是体系结构相关的。

If you look at /usr/include/stdint.h, you'll find that int64_t is defined as

typedef long long int int64_t;

So, as David said, it's compiler and not architecture dependent.

久随 2024-11-05 22:54:59

不,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 to type. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文