是否有当前使用的带有 C++ 编译器的系统,其中 int 超过 32 位宽?
Is there a currently used system with a C++ compiler where int is over 32 bits wide?
C++ 标准仅规定 int
必须 至少 16 位宽 。至少根据 cppreference,它几乎总是 16 位或 32 位宽:
data model int width in bits
----------------------------------
C++ standard at least 16
LP32 16
ILP32 32
LLP64 32
LP64 32
...
Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on Cray).
是否有当前使用的带有 C++ 编译器的系统的示例,其中 int
超过 32 位宽? 当前使用 我的意思是例如一些旧系统可能仍在被特定行业积极使用,因为有正当理由将它用于该特定任务并且不能合理地用其他东西代替。最好是 developed/worked 正在积极使用的东西,而不仅仅是系统 运行 遗留代码,它已经 20 年没有被触及了。例如用于科学计算的 64 位 int
的现代系统也是一个很好的答案。
我不是在寻找在 90 年代使用了 2 年然后完全丢弃的系统。我也不是在寻找仅用作业余爱好的东西,或者一些旧系统,世界上有两家公司使用这些系统只是因为它们太便宜而无法升级。
请注意,此答案旨在作为框架挑战;由于几点,即使是 64 位操作系统通常也不需要 >32 位。这意味着团队不太可能在没有考虑这些要点的情况下完成创建操作系统的工作,更不可能在这个时间点没有过时。我希望找到更直接的答案,但我认为这至少证明了主要操作系统的决定。
首先,您是正确的,C++ draft 允许允许宽度超过 32 位的纯整数。引用:
Note: Plain ints are intended to have the natural size suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs. — end note
强调我的
从表面上看,这似乎是在说在我的 64 位架构(以及其他所有人的架构)上,普通 int 应该具有 64 位大小;这是架构建议的尺寸,对吧?但是我必须断言,即使是 64 位架构 自然 大小 也是 32 位。规范中的引述主要用于需要 16 位纯整数的情况。
约定是一个强大的因素,从具有 32 位纯 int 的 32 位体系结构出发,如果保持 32 位,则将该源代码适应 64 位体系结构会更容易,对于设计人员和他们的用户来说都是如此两种不同的方式:
首先,系统之间的差异越小,对每个人来说就越容易。系统之间的差异只是让大多数程序员头疼的问题:它们只会让 运行 跨系统编码变得更加困难。它甚至会添加到相对罕见的情况下,在这种情况下,您无法跨具有相同发行版(仅 32 位和 64 位)的计算机执行此操作。然而,正如 John Kugelman 指出的那样,架构已经从 16 位变成了 32 位纯 int,今天可以再次经历这样的麻烦,这与他的下一点有关:
更重要的组成部分是它会导致整数大小或需要新类型的差距。因为 sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
在实际规范中,如果将 int 移动到 64 位,则强制间隙,间隙是不可避免的。它从移位 long
开始。如果将普通 int 调整为 64 位,sizeof(int) <= sizeof(long)
的约束将强制 long
至少为 64 位,并且从那里存在大小上的内在差距。由于 long
或普通 int 通常用作 32 位整数,而现在它们都不能,我们只有另一种数据类型 short
。因为 short
至少有 16 位,如果您简单地丢弃该大小,它可能会变成 32 位并填补该空白。但是 short
旨在针对 space 进行优化,因此 应该 保持这样并且 是 的用例小的,16 位的,整数也是如此。无论您如何安排尺寸,都会损失宽度,因此 int 的用例完全不可用。
这现在意味着需要更改规格,但即使设计师变得无赖,它也很可能会因更改而损坏或变得过时。持久系统的设计人员必须处理整个基础的交织代码,包括他们自己在系统中的代码、依赖项和他们想要 运行 的用户代码,并且在不考虑反响是不明智的。
附带说明一下,如果您的应用程序与 >32 位整数不兼容,您可以使用 static_assert(sizeof(int) * CHAR_BIT <= 32, "Int wider than 32 bits!");
。但是,谁知道规范 会 发生变化并且将实现 64 位普通整数,所以如果你想成为未来的证明,不要做静态断言。
我仍然认为这是一个自以为是的问题。尽管 Univac 并不常见,但仍有工作示例在展出,例如德国法兰克福附近的 technikum29 生活计算机博物馆中的 Univac 9400。人们仍在维护它的工作秩序。
"The New C Standard (Excerpted material)" 日期为 2002-2008 说:
Common Implementations
The values that are most often greater than the ones shown next are those that apply to the type int. On hosted implementations they are often the same as the corresponding values for the type long. On a freestanding implementation the processors’ efficiency issues usually dictate the use of smaller numeric ranges, so the minimum values shown here are usually used. The values used for the corresponding character, short, long, and long long types are usually the same as the ones given in the standard.
The Unisys A Series[5] is unusual in not only using sign magnitude, but having a single size (six bytes) for all non-character integer types (the type long long is not yet supported by this vendor’s implementation).
#define SHRT_MIN (-549755813887)
#define SHRT_MAX 549755813887
#define USHRT_MAX 549755813887U
#define INT_MIN (-549755813887)
#define INT_MAX 549755813887
#define UINT_MAX 549755813887U
#define LONG_MIN (-549755813887L)
#define LONG_MAX 549755813887L
#define ULONG_MAX 549755813887UL
The character type use two’s complement notation and occupies a single byte.
The C compiler for the Unisys e-@ction Application Development Solutions (formerly known as the Universal Compiling System, UCS)[6] has 9-bit character types — 18-bit short, 36-bit int and long, and 72-bit long long.
C++ 标准仅规定 int
必须 至少 16 位宽 。至少根据 cppreference,它几乎总是 16 位或 32 位宽:
data model int width in bits ---------------------------------- C++ standard at least 16 LP32 16 ILP32 32 LLP64 32 LP64 32
...
Other models are very rare. For example, ILP64 (8/8/8: int, long, and pointer are 64-bit) only appeared in some early 64-bit Unix systems (e.g. Unicos on Cray).
是否有当前使用的带有 C++ 编译器的系统的示例,其中 int
超过 32 位宽? 当前使用 我的意思是例如一些旧系统可能仍在被特定行业积极使用,因为有正当理由将它用于该特定任务并且不能合理地用其他东西代替。最好是 developed/worked 正在积极使用的东西,而不仅仅是系统 运行 遗留代码,它已经 20 年没有被触及了。例如用于科学计算的 64 位 int
的现代系统也是一个很好的答案。
我不是在寻找在 90 年代使用了 2 年然后完全丢弃的系统。我也不是在寻找仅用作业余爱好的东西,或者一些旧系统,世界上有两家公司使用这些系统只是因为它们太便宜而无法升级。
请注意,此答案旨在作为框架挑战;由于几点,即使是 64 位操作系统通常也不需要 >32 位。这意味着团队不太可能在没有考虑这些要点的情况下完成创建操作系统的工作,更不可能在这个时间点没有过时。我希望找到更直接的答案,但我认为这至少证明了主要操作系统的决定。
首先,您是正确的,C++ draft 允许允许宽度超过 32 位的纯整数。引用:
Note: Plain ints are intended to have the natural size suggested by the architecture of the execution environment; the other signed integer types are provided to meet special needs. — end note
强调我的
从表面上看,这似乎是在说在我的 64 位架构(以及其他所有人的架构)上,普通 int 应该具有 64 位大小;这是架构建议的尺寸,对吧?但是我必须断言,即使是 64 位架构 自然 大小 也是 32 位。规范中的引述主要用于需要 16 位纯整数的情况。
约定是一个强大的因素,从具有 32 位纯 int 的 32 位体系结构出发,如果保持 32 位,则将该源代码适应 64 位体系结构会更容易,对于设计人员和他们的用户来说都是如此两种不同的方式:
首先,系统之间的差异越小,对每个人来说就越容易。系统之间的差异只是让大多数程序员头疼的问题:它们只会让 运行 跨系统编码变得更加困难。它甚至会添加到相对罕见的情况下,在这种情况下,您无法跨具有相同发行版(仅 32 位和 64 位)的计算机执行此操作。然而,正如 John Kugelman 指出的那样,架构已经从 16 位变成了 32 位纯 int,今天可以再次经历这样的麻烦,这与他的下一点有关:
更重要的组成部分是它会导致整数大小或需要新类型的差距。因为 sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)
在实际规范中,如果将 int 移动到 64 位,则强制间隙,间隙是不可避免的。它从移位 long
开始。如果将普通 int 调整为 64 位,sizeof(int) <= sizeof(long)
的约束将强制 long
至少为 64 位,并且从那里存在大小上的内在差距。由于 long
或普通 int 通常用作 32 位整数,而现在它们都不能,我们只有另一种数据类型 short
。因为 short
至少有 16 位,如果您简单地丢弃该大小,它可能会变成 32 位并填补该空白。但是 short
旨在针对 space 进行优化,因此 应该 保持这样并且 是 的用例小的,16 位的,整数也是如此。无论您如何安排尺寸,都会损失宽度,因此 int 的用例完全不可用。
这现在意味着需要更改规格,但即使设计师变得无赖,它也很可能会因更改而损坏或变得过时。持久系统的设计人员必须处理整个基础的交织代码,包括他们自己在系统中的代码、依赖项和他们想要 运行 的用户代码,并且在不考虑反响是不明智的。
附带说明一下,如果您的应用程序与 >32 位整数不兼容,您可以使用 static_assert(sizeof(int) * CHAR_BIT <= 32, "Int wider than 32 bits!");
。但是,谁知道规范 会 发生变化并且将实现 64 位普通整数,所以如果你想成为未来的证明,不要做静态断言。
我仍然认为这是一个自以为是的问题。尽管 Univac 并不常见,但仍有工作示例在展出,例如德国法兰克福附近的 technikum29 生活计算机博物馆中的 Univac 9400。人们仍在维护它的工作秩序。
"The New C Standard (Excerpted material)" 日期为 2002-2008 说:
Common Implementations
The values that are most often greater than the ones shown next are those that apply to the type int. On hosted implementations they are often the same as the corresponding values for the type long. On a freestanding implementation the processors’ efficiency issues usually dictate the use of smaller numeric ranges, so the minimum values shown here are usually used. The values used for the corresponding character, short, long, and long long types are usually the same as the ones given in the standard.
The Unisys A Series[5] is unusual in not only using sign magnitude, but having a single size (six bytes) for all non-character integer types (the type long long is not yet supported by this vendor’s implementation).
#define SHRT_MIN (-549755813887)
#define SHRT_MAX 549755813887
#define USHRT_MAX 549755813887U
#define INT_MIN (-549755813887)
#define INT_MAX 549755813887
#define UINT_MAX 549755813887U
#define LONG_MIN (-549755813887L)
#define LONG_MAX 549755813887L
#define ULONG_MAX 549755813887UL
The character type use two’s complement notation and occupies a single byte.
The C compiler for the Unisys e-@ction Application Development Solutions (formerly known as the Universal Compiling System, UCS)[6] has 9-bit character types — 18-bit short, 36-bit int and long, and 72-bit long long.