难道一个int的大小取决于编译器和/或处理器? [英] Does the size of an int depend on the compiler and/or processor?

查看:193
本文介绍了难道一个int的大小取决于编译器和/或处理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问一个整数的大小取决于编译器,操作系统和处理器?

Would the size of an integer depend upon the compiler, OS and processor?

推荐答案

在这个问题的答案取决于我们是从实际考虑在多大程度上愿意得到。

The answer to this question depends on how far from practical considerations we are willing to get.

最终,在理论上,一切都在C和C ++依赖于编译器和仅在编译器。硬件/操作系统并不重要的。编译器可以自由实现的任何的厚度的硬件抽象层和仿真不惜一切代价。没有什么可以prevent C或从实施 INT 类型的任何尺寸,用任何重新presentation C ++实现,只要它足够大,以满足在语言标准中规定的最低要求。抽象这样的水平的实际例子都是现成的,例如基于虚拟机的平台,像Java编程语言。

Ultimately, in theory, everything in C and C++ depends on the compiler and only on the compiler. Hardware/OS is of no importance at all. The compiler is free to implement a hardware abstraction layer of any thickness and emulate absolutely anything. There's nothing to prevent a C or C++ implementation from implementing the int type of any size and with any representation, as long as it is large enough to meet the minimum requirements specified in the language standard. Practical examples of such level of abstraction are readily available, e.g. programming languages based on "virtual machine" platform, like Java.

Howerver,C和C ++的目的是高度的有效的语言。为了达到最高的效率C或C ++实现必须考虑到从底层硬件衍生帐户的某些因素。出于这个原因,它使一个很大的意义,以确保每个基本类型是基于硬件支持一些重新presentation直接(或几乎直接)。在这个意义上,基本类型的大小不依赖于硬件。

Howerver, C and C++ are intended to be highly efficient languages. In order to achieve maximum efficiency a C or C++ implementation has to take into account certain considerations derived from the underlying hardware. For that reason it makes a lot of sense to make sure that each basic type is based on some representation directly (or almost directly) supported by the hardware. In that sense, the size of basic types do depend on the hardware.

在换句话说,一个特定的C或C ++实现对64位硬件/ OS平台是完全免费的实施 INT 为71位1's补签署占用内存为128位,使用其他57位作为总是需要存储编译器作者的女朋友的生日填充位整型。此实现甚至将有一定的实用价值:它可以被用于执行的C / C ++程序可移植性的运行时间检验。但是,这也正是该实现的实用性将结束。不要指望能看到类似的东西在一个正常的C / C ++编译器。

In other words, a specific C or C++ implementation for a 64-bit hardware/OS platform is absolutely free to implement int as a 71-bit 1's-complement signed integral type that occupies 128 bits of memory, using the other 57 bits as padding bits that are always required to store the birthdate of the compiler author's girlfriend. This implementation will even have certain practical value: it can be used to perform run-time tests of the portability of C/C++ programs. But that's where the practical usefulness of that implementation would end. Don't expect to see something like that in a "normal" C/C++ compiler.

这篇关于难道一个int的大小取决于编译器和/或处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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