简体   繁体   English

C / C ++中数据类型名称的含义

[英]Meaning of data type names in C/C++

In C and C++, the size of the build-in integer types is implementation dependent. 在C和C ++中,内置整数类型的大小取决于实现。 But is there any predefined intended meaning of them such that int should represent the machine word size etc? 但是,它们是否有任何预定义的预期含义,以便int可以表示机器字的大小等?

Historically, int was supposed to mean the most "natural" type for an integer on the machine hardware; 从历史上看, int被认为是机器硬件上整数的最“自然”类型。 obviously, "natural" is somewhat subjective, but in the past, it was usually pretty obvious, and there weren't that many integral types available anyway, so makeing int the same size as a long or a short was the normal course of things. 显然,“自然”在某种程度上是主观的,但是在过去,它通常很明显,而且反正没有太多整数类型可用,因此使intlongshort大小相同是正常的做法。

For various reasons, most 64 bit platforms make int 32 bits. 由于各种原因,大多数64位平台将int 32位。 One could easily argue that this isn't the most "natural" length, but there was a desire that 32 bit integers be the default, and int is clearly the default integral type. 可以很容易地认为这不是最“自然的”长度,但是人们希望32位整数是默认整数,而int显然是默认整数类型。 Whether it is the most natural for the architecture or not becomes secondary to whether it is the size wanted as a default. 对于体系结构来说是否最自然,是否成为默认大小是次要的。

With regards to word size: historically, this was the most natural, but in many ways, it's not clear what is meant by "word size" on a modern machine: the largest size you can do arithmetic on? 关于字长:从历史上看,这是最自然的,但是在许多方面,尚不清楚现代机器上的“字长”是什么意思:您可以算术运算的最大字长? the size of bus transfers to and from memory? 往返于内存的总线传输大小? etc. Traditionally, "word size" has been used to mean both the width of internal registers (when the machine had them), or the size of a basic bus transfer. 传统上,“字长”用于表示内部寄存器的宽度(当机器拥有它们时)或基本总线传输的大小。 (The 8088 was usually referred to as an 8 bit machine, although it had 32 bit registers.) I wouldn't put too much meaning in it today. (尽管8088具有32位寄存器,但通常被称为8位计算机。)今天,我不会在其中添加太多含义。

There's some wording on that, but it's not very rigid: 上面有一些措辞,但不是很刻板:

Objects declared as characters (char) shall be large enough to store any member of the implementation's basic character set. 声明为字符(char)的对象应足够大以存储实现的基本字符集的任何成员。

There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”. 有五种标准的带符号整数类型:“带符号字符”,“ short int”,“ int”,“ long int”和“ long long int”。 In this list, each type provides at least as much storage as those preceding it in the list. 在此列表中,每种类型提供的存储量至少与列表中位于其前面的类型相同。 (...) Plain ints have the natural size suggested by the architecture of the execution environment , the other signed integer types are provided to meet special needs. (...) 普通整数具有执行环境的体系结构建议的自然大小 ,还提供了其他有符号整数类型以满足特殊需要。

No strict recommendations about float sizes either: 也没有关于浮子尺寸的严格建议:

There are three floating point types: float, double, and long double. 共有三种浮点类型:float,double和long double。 The type double provides at least as much precision as float, and the type long double provides at least as much precision as double. double类型至少提供与float一样高的精度,long long类型提供至少与double一样高的精度。 (...) The value representation of floating-point types is implementation-defined. (...) 浮点类型的值表示形式是实现定义的。

C, unlike Java, was designed as a platform enabler and not a stand-alone platform. 与Java不同,C被设计为平台支持者,而不是独立平台。 Cross platform compatibility took a much lower priority than working with data-type sizes that worked optimally for the given platform. 与使用对给定平台最佳工作的数据类型大小相比,跨平台兼容性的优先级要低得多。 Integer types are therefore not specified by the C standard and are totally platform specific 因此,C标准未指定整数类型,并且整数类型完全是平台特定的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM