‹ 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. entrope · · focus · HN ↗
      > Shouldn't they be 64 bits on most modern systems then?

      Arguably so, but then one would lose the ability to natively name 16-bit integer types because "short" would be 32 bits.

      An earlier comment addresses x86-64. AArch64 (pedantically, the A64 instruction set used for AArch64&#x27;s 64-bit execution mode) is similar, in that addresses are 64 bits wide but ALU instructions typically encode a width bit, called &quot;sf&quot;, that selects either 32- or 64-bit data registers and arithmetic. See, for example, <a href="https:&#x2F;&#x2F;arm.jonpalmisc.com&#x2F;latest_aarch64&#x2F;add_addsub_ext" rel="nofollow">https:&#x2F;&#x2F;arm.jonpalmisc.com&#x2F;latest_aarch64&#x2F;add_addsub_ext .

      1. imtringued · · focus · HN ↗
        char is at least 8 bits, short is at least 16 bits, long is at least 32 bits, long long is at least 64 bits.

        Not sure how what you said makes sense.

        1. debugnik · · focus · HN ↗
          long can&#x27;t be smaller than int, so a 64-bit int leaves short as the only type between char and long long, and you need to pick whether it&#x27;s 16 bits or 32.

          Then again, we&#x27;d still have stdint around. And ultimately this doesn&#x27;t matter because most code isn&#x27;t portable anyway.

          1. matvore · · focus · HN ↗
            You would still want a native 16 bit type in order to have a pointer to a 16-bit memory location, including an array of 16-bit values.
            1. [deleted] · · focus · HN ↗

              [deleted]

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.