‹ BackHN Continuity

Thread

C's Flexible Integer Sizes Were Not a Design Mistake

113 points · 166 comments · ibobev

  1. layer8 · · focus · HN ↗
    > Language types such as char, int, short, and long do not come with a guarantee of how many bytes they occupy in memory.

    Char is actually guaranteed by C to occupy exactly 1 byte in memory. It’s just that a byte can have more than eight bits in C. “Byte” is simply the smallest unit of memory addressable by a pointer.

    Further down the article acknowledges that “C requires char to have at least 8 bits (CHAR_BIT >= 8), not exactly 8” and mentions the Honeywell 6000 as an example of a C implementation with 9 bits (and 36-bit ints).

    Historically in computing, the size of a byte was hardware-dependent and not standardized. The Wikipedia article on “byte” cites Knuth’s 1968 TAOCP where byte denotes a unit which “contains an unspecified amount of information […] capable of holding at least 64 distinct values […] at most 100 distinct values. On a binary computer a byte must therefore be composed of six bits”.

    1. kvemkon · · focus · HN ↗
      > C requires char to have at least 8 bits (CHAR_BIT >= 8)

      The famous TI C55x DSP with 16 bits byte for example: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=3112704">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=3112704.

      And they are still available new for purchase.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.