What is a “byte” in C / C++

坚强是说给别人听的谎言 提交于 2019-11-30 21:49:32

问题


For example, here's a reference for fread:

size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );

Reads an array of count elements, each one with a size of "size bytes"... So how many BITS will read an fread(&x, 1, 1, stream)? Eight or CHAR_BIT?


回答1:


C99, §3.6:

byte

addressable unit of data storage large enough to hold any member of the basic character set of the execution environment

and §5.2.4.2.1:

CHAR_BIT — number of bits for smallest object that is not a bit-field (byte)

Thus, a "byte" contains CHAR_BIT bits.




回答2:


CHAR_BIT. The bit width of a byte is implementation-defined and is available to the developer via the CHAR_BIT macro.



来源:https://stackoverflow.com/questions/8296426/what-is-a-byte-in-c-c

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