为什么POSIX任务CHAR_BIT == 8? [英] Why did POSIX mandate CHAR_BIT==8?

查看:150
本文介绍了为什么POSIX任务CHAR_BIT == 8?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个在POSIX理一张纸条,上面强制CHAR_BIT是8是一个让步提出,有必要保持与C99定位不扔出去插座/网络,但我从来没有见过的完全冲突是什么解释。有没有人有,为什么认为有必要轶事或引用?

There's a note in the POSIX rationale that mandating CHAR_BIT be 8 was a concession made that was necessary to maintain alignment with C99 without throwing out sockets/networking, but I've never seen the explanation of what exactly the conflict was. Does anyone have anecdotes or citations for why it was deemed necessary?

编辑:我已经得到关于为什么这是可取的 CHAR_BIT 为8大量投机性的答案,我同意,但什么我真正需要的是什么C99之间以及网络的东西,在POSIX的技术冲突。我最好的猜测是,它已经是与C99要求 UINT * _t 确切大小类型(不填充),而 inttypes.h previously在POSIX做没有这样的规定。

I've gotten a lot of speculative answers regarding why it's desirable for CHAR_BIT to be 8, and I agree, but what I'm really looking for is what the technical conflict between C99 and the networking stuff in POSIX is. My best guess is that it has something to do with C99 requiring uint*_t to be exact-sized types (no padding) whereas the inttypes.h previously in POSIX made no such requirement.

推荐答案

由于绝大多数标准(与通信)进行ANSI和ISO谈话八位字节(8位值)的条款。却无人软弱无力可变大小的性格废话: - )

Because the vast majority of standards (related to communication) out of ANSI and ISO talk in terms of octets (8-bit values). There is none of that wishy-washy variable-sized character nonsense :-)

此外,由于采用C code的相当大的数量字符 unsigned char型用于存储和/或操纵这些值,并且假设他们是8位,即允许ISO可变大小将导致该code问题的事实。

And, since a rather large quantity of C code used char or unsigned char for storing and/or manipulating these values, and assumed they were 8 bits wide, the fact that ISO allowed a variable size would cause problems for that code.

记住的ISO C的压倒一切的目标之一 - 现有code是重要的,现有的实现都没有。这就是为什么 limits.h中摆在首位,而不是仅仅假定特定值的存在,因为当时周围的假设,否则code。

Remember one of the over-riding goals of ISO C - existing code is important, existing implementations are not. This is one reason why limits.h exists in the first place rather than just assuming specific values, because there was code around that assumed otherwise.

POSIX也遵循相同的准则。通过授权8比特的字节大小,它们$ P $在现实世界pvented巨大code量的破损已经

POSIX also followed that same guideline. By mandating a byte size of 8 bits, they prevented the breakage of a huge amount of code already in the real world.

这篇关于为什么POSIX任务CHAR_BIT == 8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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