0

In the C Standard f.e. (my reference is especially ISO/IEC 9899:2011 (C11)) under §3.6 is stated:

3.6

1 byte

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

2 NOTE 1 It is possible to express the address of each individual byte of an object uniquely.

3 NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementationdefined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit.

Why is that so? I thought the size of a byte is absolute fixed in the technology of information to be comprised of exactly 8 bits.

Why does the Standard makes this seemingly crazy statement?

Also: If the byte size isn´t fixed, how we can talk about f.e. a char to be comprised of 8 bits and an int of 32 bits (4 Bytes), assuming 64-bit systems?

  • Seems a close enough question to https://stackoverflow.com/questions/32091992/is-char-bit-ever-8 – StoryTeller - Unslander Monica Dec 14 '19 at 16:20
  • 2
    And who promised `int` is 32 bits? – StoryTeller - Unslander Monica Dec 14 '19 at 16:20
  • There's also https://stackoverflow.com/questions/2215445/are-there-machines-where-sizeofchar-1-or-at-least-char-bit-8 and https://stackoverflow.com/questions/21080114/if-char-bit-8-what-is-the-size-of-other-types – StoryTeller - Unslander Monica Dec 14 '19 at 16:22
  • @StoryTeller-UnslanderMonica First, Thank you very much for your research, to help me, I`m going through the provided questions. But i can´t find an explanation until now, why is it so, in there. Can you answer this question. That would be nice. – RobertS supports Monica Cellio Dec 14 '19 at 16:26
  • 1
    The other questions mention architectures, some quite recent, where a "byte" is more than 8 bits. I think chux's answer summarizes nicely why the standard would not fix a byte size in bits given such machines still exist today. – StoryTeller - Unslander Monica Dec 14 '19 at 16:27
  • 2
    I worked on a machine called "Varian72". It simply did not have instructions to read just 8 bits. It had 32,678 addresses, each of which referred to a 16-bit value. A C compiler would be forced to use a 16-bit byte (or larger) on this system. – ikegami Dec 14 '19 at 17:53
  • An *octet* is exactly 8 bits. A byte is as many bits as the hardware designer wants it to be. Powers of 2 are convenient, such that 8-bit bytes and 16/32/64-bit words are the norm, but there’s nothing magic about them. There have historically been machines with 9-bit bytes and 36-bit words. There have been machines that weren’t byte-addressed at all, using words of anywhere from 16 to 40 bits wide. – John Bode Dec 15 '19 at 05:39

1 Answers1

5

I thought the size of a byte is absolute fixed in the technology of information to be comprised of exactly 8 bits.

No. That is the evolution of "byte" which is now so commonly 8.

Other values of 9, 16, 18, 32, 64 .... have occurred for various technical (and business) reason. Their rarity today does make it surprising that CHAR_BIT could be anything but 8.

Recall C is very portable and accommodates a wide range of architectures.


If the byte size isn´t fixed, how we can talk about f.e. a char to be comprised of 8 bits and an int of 32 bits (4 Bytes), assuming 64-bit systems?

In C, you cannot - in general. A char might by 9 bits or 64, etc. Such systems are rare these days.

Avoid "assuming 64-bit systems" as a requirement to drive int size to some width. More factors apply.

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256