Can the Size of the Byte greater than octet 8 bits

醉酒当歌 提交于 2019-12-18 09:43:03

问题


I was going through http://www.parashift.com/c++-faq/index.html and there I found that byte can also be 64 bits http://www.parashift.com/c++-faq/very-large-bytes.html. Is it possible and what is the use of that much amount of storage capacity for a byte?


回答1:


The point isn't the usefulness of a big-byte "per se", but the fact that, for the standard, a byte is the smallest addressable quantity on the system1; if a system cannot address its memory in units smaller than 64 bits, then char will be 64 bit.

Obviously it's almost impossible to find such strange stuff on modern general-purpose computers, these weirdnesses come out on very specialized hardware (I heard DSPs are particularly prone to this kind of stuff), usually for performance reasons.

You can see more about this in this other FAQ.


  1. As far as is larger than 8 bits and is capable of holding a basic set of characters (alphanumeric characters plus some symbol, IIRC).



回答2:


The key define you are looking for is CHAR_BIT which is only guaranteed in C99(and correspondingly modern C++ systems) to be >=8. POSIX requires CHAR_BIT to == 8.

As mentioned, the real reason it is not just fixed at 8 for all systems are DSPs, which simplify their addressing mechanisms for speed to only allow one alignment for the architecture word size. Most modern DSPs are 16 or 32 bit, but I'd imagine some are 64-bit as well.

If you actually have code where this matters, you can use CHAR_BIT to compute 8-bit chunks from bytes, which should optimize out on CHAR_BIT==8 platforms.



来源:https://stackoverflow.com/questions/14421101/can-the-size-of-the-byte-greater-than-octet-8-bits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!