‹ BackHN Continuity

Thread

C's Flexible Integer Sizes Were Not a Design Mistake

113 points · 166 comments · ibobev

  1. RobotToaster · · focus · HN ↗
    > A 'plain' int object has the natural size suggested by the architecture of the execution environment.

    Shouldn't they be 64 bits on most modern systems then?

    1. quelsolaar · · focus · HN ↗
      One a modern computer, the ideal integer type is usually smaller than 64 bits. Even though the arithmetic units handle 64 bits in one op, 64 bits take up twice the memory bandwidth, and half as many fits in a cache-line, and given that a modern computer is usually bound by memory access, smaller is better. So you can argue that both new and old computers prefer 32 bit over 64, but for different reasons.

      The added compatibility between 32 and 64 bit systems, is another reason. Also if you choose int to be 64 bits, what would you make short? 16 or 32 bits? It makes much more sense to keep int 32 bits, and reserve long / long long for 64 bits.

      1. someonebaggy · · focus · HN ↗
        It does, and then you've abandoned the whole principle of natural-sized types and you just have weird ways of spelling int8, int16, int32, int64.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.