It is possible to write less than 1 byte to a file

前端 未结 4 2027
忘了有多久
忘了有多久 2021-02-19 09:00

As far as I know the smallest unit in C is a byte. Where does this constraint comes from? CPU?

For example, how can I write a nibble or a singl

4条回答
  •  灰色年华
    2021-02-19 09:54

    Actually, it's a char--byte is not a standard C type.

    The constraint comes from the C standard and is tautological: char is the smallest complete type in C because it is defined as such, and the sizes of all other types are defined as multiples of the size of char (whose size is always 1.)

    Now, the number of bits in a char can vary from platform to platform. The number of bits tends to ultimately be hardware-defined, though most systems these days use 8-bit chars. char is supposed to represent the smallest addressable unit of memory (again, by definition.)

提交回复
热议问题