【发布时间】:2012-10-10 15:29:44
【问题描述】:
我在标准中找到:
整数类型的表示应使用纯二进制计数系统定义值
但我的理解是,这并不是 C++ 必须在基于硬件基础 2 的机器上实现的要求;换句话说,这似乎只是程序员应该看到的要求。
C++ 标准是否需要二进制 CPU,或者是否可以在三进制或十进制机器上实现有效的 C++ 实现?
微小的背景信息:在历史上,已经有使用小数、三进制或 C++ 字节长度为 36 位的计算机 (PDP-10)
【问题讨论】:
-
很难看出例如按位运算符可以在非二进制架构上工作,除非您在两者之间有某种二进制虚拟机,在这种情况下,底层架构没有实际意义。
-
标准中的那一段对我来说似乎很清楚。它需要一台能够对数字进行二进制表示的机器。换句话说,一台典型的现代数字计算机,或者至少是一台可以模拟二进制数的计算机。
-
N3337 3.9.1 Fundamental typesTypes bool, char, char16_t, char32_t, wchar_t, and the signed and unsigned integer types are collectively called integral types. A synonym for integral type is integer type. The representations of integral types shall define values by use of a pure binary numeration system. [ Example: this International Standard permits 2's complement, 1's complement and signed magnitude representations for integral types. —end example ]我想这可能属于“好像”。 -
还有
N3337 4.7 Integral conversionsIf the destination type is unsigned, the resulting value is the least unsigned integer congruent to the source integer (modulo 2^n where n is the number of bits used to represent the unsigned type). [ Note: In a two's complement representation, this conversion is conceptual and there is no change in the bit pattern (if there is no truncation). —end note ]
标签: c++ language-lawyer