什么是长期的历史背景和int往往是相同的大小? [英] What is the historical context for long and int often being the same size?

查看:108
本文介绍了什么是长期的历史背景和int往往是相同的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据众多的答案在这里, INT 是在C和C通用平台尺寸32位++(Windows和放大器; Linux中,32安培; 64位)(我知道,有没有标准的,但在实践中,这些是所观察到的尺寸。)

According to numerous answers here, long and int are both 32 bits in size on common platforms in C and C++ (Windows & Linux, 32 & 64 bit.) (I'm aware that there is no standard, but in practice, these are the observed sizes.)

我的问题是,究竟是怎么来的呢?为什么我们有两种类型的大小相同?我previously总是假定将大部分的时间64位, INT 32.我不是说应该的一种方式或其他,我只是好奇,我们如何来到这里。

So my question is, how did this come about? Why do we have two types that are the same size? I previously always assumed long would be 64 bits most of the time, and int 32. I'm not saying it "should" be one way or the other, I'm just curious as to how we got here.

推荐答案

从的 C99理由(PDF)一节6.2.5:

[...] 1970年,16位C(对于
  PDP-11)第一重presented文件
  与16位整数的信息,
  这很快被废弃盘
  进展。人转换到32位的
  文件系统,首先使用 INT [2]
  该结构不仅
  尴尬,但也不能有效地
  移植到32位硬件。

[...] In the 1970s, 16-bit C (for the PDP-11) first represented file information with 16-bit integers, which were rapidly obsoleted by disk progress. People switched to a 32-bit file system, first using int[2] constructs which were not only awkward, but also not efficiently portable to 32-bit hardware.

要解决这个问题,键入
  加入到该语言,即使
  这要求C的PDP-11
  生成多个操作
  模拟32位运算。即使
  32位小型机面世
  沿着16位系统,人们仍然
  使用 INT 求效益,以保留
  的情况下,较大的整数
  是真正需要的,因为
  明显在16位效率较低
  系统。无论分别为
  加入到C,使可用
  对于16位, 32位,
   INT 作为方便的性能。
  没有锁定的欲望
  号16或32到语言,因为
  存在着C编译器,至少
  24位和36位CPU,而是
  提供了可用于名称
  32位需要。

To solve the problem, the long type was added to the language, even though this required C on the PDP-11 to generate multiple operations to simulate 32-bit arithmetic. Even as 32-bit minicomputers became available alongside 16-bit systems, people still used int for efficiency, reserving long for cases where larger integers were truly needed, since long was noticeably less efficient on 16-bit systems. Both short and long were added to C, making short available for 16 bits, long for 32 bits, and int as convenient for performance. There was no desire to lock the numbers 16 or 32 into the language, as there existed C compilers for at least 24- and 36-bit CPUs, but rather to provide names that could be used for 32 bits as needed.

的PDP-(11)C可能已经
  重新实现与 INT 为32位,
  从而避免了需要长;但
  会作出改变的人
   INT 的大多数用途为
  遭受严重的性能下降
  在PDP-11。除了
  源$ C ​​$ C的潜在影响,
  在现有的对象code的影响,
  数据文件将会变得更糟,甚至
  在1976年到20世纪90年代,随着一个巨大的
  软件的安装基础,并与
  wides $ P $垫采用动态链接
  库,改变的影响
  在一个共同的数据对象的大小
  现有的环境是如此之高,
  很少有人会容忍它,虽然
  在创建时,它是可以接受的
  新环境。因此,许多供应商,
  为避免名字空间的冲突,有
  添加到其32位一64位整数
  采用新的名称,C环境
  其中长长一直是最
  广泛使用。 [...]

PDP-11 C might have been re-implemented with int as 32-bits, thus avoiding the need for long; but that would have made people change most uses of int to short or suffer serious performance degradation on PDP-11s. In addition to the potential impact on source code, the impact on existing object code and data files would have been worse, even in 1976. By the 1990s, with an immense installed base of software, and with widespread use of dynamic linked libraries, the impact of changing the size of a common data object in an existing environment is so high that few people would tolerate it, although it might be acceptable when creating a new environment. Hence, many vendors, to avoid namespace conflicts, have added a 64-bit integer to their 32-bit C environments using a new name, of which long long has been the most widely used. [...]

这篇关于什么是长期的历史背景和int往往是相同的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆