在 Java 和 .net 中,默认的 int 都是 32 位的。这是否与当 java 和 .net 出现时,大多数使用的处理器都是 32 位的事实有关?还是有其他原因选择 32 作为整数的默认位长?
问问题
146 次
2 回答
4
是的,这主要是因为大多数处理器都是 32 位的。这也显示在 Java 规范的其他部分。例如,明确不保证long
和double
(64 位)读取和写入是原子的,而对于所有其他原始类型,它是原子的。
于 2013-03-17T21:40:38.850 回答
2
Java was based on C and some C++.
In C char
is 8-bit, short
is 16-bit and a long long
is 64-bit. An int
could be 16-bit or 32-bit but for simplicity in Java they decided on byte
being 8-bit, short
is 16-bit, int
is 32-bit and long
is 64-bit. In Java char
is 16-bit unsigned.
In short, from C there were four types and four sizes and so int
ended up being 32-bit.
于 2013-03-17T21:50:34.383 回答