‹ BackHN Continuity

Thread

C's Flexible Integer Sizes Were Not a Design Mistake

113 points · 166 comments · ibobev

  1. quelsolaar · · focus · HN ↗
    Good article.

    C would probably not have survived unless it had this flexibility.

    But its not justa historical thing. Today there are modern platforms like DSPs that have 32bit sized char, because that is the smallest addressable type. These platforms depend on C for tool chains, even if most "portable" C wont run correctly on them. The fact that you can build hardware like that, and not have to invent a new language / dialect to program them is a huge win for the world.

    <edit> I didnt see the footnote about DSPs at first read </edit>

    1. pjmlp · · focus · HN ↗
      C survived because UNIX carried it.
      1. flohofwoe · · focus · HN ↗
        I don't agree. UNIX was an extremely niche operating system until Linux won the data center, at that time both C and C++ were already extremely popular outside the UNIX world. C won because it was so easy to adapt to new hardware architectures (even GPU shading languages are just minimally extended flavours of C and C++).
        1. prerok · · focus · HN ↗
          Sorry, what? Most of data centers were running a UNIX operating system back in the day. What operating system do you think they were running?
          1. fragmede · · focus · HN ↗
            WindowsNT was the other operating system of that time.
            1. pjmlp · · focus · HN ↗
              With Win32, OS/2 and POSIX subsystems.
            2. prerok · · focus · HN ↗
              That's way way later. UNIXes were the ones running in 70s and 80s. WindowsNT and Linux only later came to take a slice and, still later on, Linux won the day. How anyone would consider UNIX "niche" is beyond me.
              1. fragmede · · focus · HN ↗
                In the other direction then, IBM mainframes.
                1. pjmlp · · focus · HN ↗
                  IBM mainframes added a UNIX subsystem in the 1990s, starting with UNIX for MVS, nowadays z/OS UNIX.

                  DEC's VAX/VMS became Open VMS when UNIX/POSIX support was added in the early 1990's as well.

                  Other mainframe systems added similar POSIX environments.

                  The way Windows NT OS linage works isn't something novel, it is how mainframes have introduced multiple OS personalities and virtualisation modes since the late 70's.

          2. tialaramex · · focus · HN ↗
            There is a weird moment toward the end of the 1990s when Microsoft is trying to show their NT is a serious competitor in this space.

            Traditionally this was a profitable niche, Microsoft would like to take a fat piece of that, and instead what happened is that Linux destroyed the profit margin. A million dollars overhead that would have kept a hungry UNIX® vendor alive on your project didn't turn into an extra million dollars on Microsoft's balance sheet, instead it evaporated because Linux is "free". And so then Microsoft lost interest.

            1. pjmlp · · focus · HN ↗
              Yeah, and one of the ways to show it was a serious OS for DoD projects was to have a POSIX subsystem, which had they kept it around, Linux would never have taken off on the PC, and there would be no need for WSL 40 years later.
              1. tialaramex · · focus · HN ↗
                The POSIX subsystem is a box checking exercise. The reason the box was there isn't satisfied but the box was checked and Microsoft hoped that's good enough. If you need "a Unix" and they give you NT and circle the stuff about POSIX you don't go "Oh, perfect" you ask them to fix the requirements document so that you can have an actual Unix next time.

                WSL is Redmond going OK yeah, here you go, an actual Unix.

                1. pjmlp · · focus · HN ↗
                  There was also SUA and Interix in the meantime, before WSL came to be.

                  The point still stands, that POSIX checkbox was relevant enough for spending the money in engineers salary during Windows NT 3.51 development.

                  1. someonebaggy · · focus · HN ↗
                    It was a requirement on government contract tenders. If you didn't support POSIX, you didn't get the contract and the government would have continued using SunOS or AIX or something instead of Windows NT. Remember that POSIX was designed to make these OSes somewhat interchangeable - they wouldn't order something they knew was incompatible with everything they already had.
                    1. pjmlp · · focus · HN ↗
                      Exactly, thus UNIX/POSIX being everywhere that mattered, alongside the language created to make UNIX portable, C.

                      For those that don't read standards, POSIX certification requires the existence of a C compiler, the more recent one being C17 compliant.

                      <a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9799919799&#x2F;utilities&#x2F;c17.html" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9799919799&#x2F;utilities&#x2F;c...

            2. iberator · · focus · HN ↗
              Worth to mention that in the 80&quot; Microsoft was the biggest UNIX vendor with their XENIX operating system:)
        2. pjmlp · · focus · HN ↗
          Most people only cared about C, because they needed to work on UNIX, and UNIX was taking over the server room and all 1980&#x27;s graphical workstations.

          C was pretty much ignored on 8 bit home computers, outside some toy compilers for CP&#x2F;M.

          In the 16 bit days, it was yet another language alongside BASIC compilers, Pascal, Modula-2, Assembly.

          C is so tied to UNIX, that POSIX had to be created so that any non-UNIX operating system could provide a cozy home for their C compilers.

          UNIX&#x2F;POSIX is for all practical purposes the runtime most C applications rely on, there are naturally some exceptions like free-standing or Windows (which eventually gave up and add to start improving its support).

          It is only due to historical accident that Microsoft gave up on Xenix, instead of replacing their MS-DOS efforts.

          1. jstimpfle · · focus · HN ↗
            I don&#x27;t know about you but I need zero POSIX to write C on Windows. Not even much of the (mostly bad) C standard library. I use snprintf for convenience (but I don&#x27;t have to), and memcpy, that&#x27;s about it.

            And many projects properly abstract their OS layer so they aren&#x27;t tied to POSIX.

            Maybe Unix is tied to C, but C isn&#x27;t tied to Unix.

            1. pjmlp · · focus · HN ↗
              You failed to read this sentence until the end,

              &gt; UNIX&#x2F;POSIX is for all practical purposes the runtime most C applications rely on, there are naturally some exceptions like free-standing or Windows (which eventually gave up and add to start improving its support).

              1. jstimpfle · · focus · HN ↗
                Point is that C isn&#x27;t tied to POSIX. It&#x27;s just not. Of course there are apps created on e.g. Linux, those sometimes get ported by relying on standardized &quot;POSIX&quot; platform. But that&#x27;s not how you have to program, and it isn&#x27;t a great way to program. And it isn&#x27;t a sufficient platform to do anything useful.
        3. imtringued · · focus · HN ↗
          Disclaimer: This is just some cursory research using LLMs.

          C was invented to rewrite UNIX in a programming language that made it easy to port UNIX between machines.

          So what you&#x27;re saying is contradictory. You&#x27;re saying the underlying motivation of C was wrong or unnecessary (porting UNIX to different hardware architectures) but C won because that underlying motivation (easy porting between hardware architectures) was partially right.

          Your position is now that C didn&#x27;t need UNIX as a stopgap, which is weird because your argument gains no weight (basically saying C&#x27;s dominance is sheer coincidence) if it&#x27;s true but if it&#x27;s false you&#x27;re just plain wrong.

          1. flohofwoe · · focus · HN ↗
            My point is that C&#x27;s popularity quickly outgrew the popularity of UNIX, especially during most of the 1990s before Linux made UNIX accessible to us &quot;PC peasants&quot;. Most 1990s PC games were written in C, and C was also the dominant high level language on 16&#x2F;32 bitters like the Amiga or Atari ST.
            1. pjmlp · · focus · HN ↗
              Nope, they were mostly written in Assembly.

              On the consoles it took until PlayStation for C to take off among game devs.

              Additionally many Amiga games used Blitz BASIC and AMOS.

              Anyone involved in the Demoscene early days would be 100% Assembly as well.

              On PC, it required until Watcom with its great MS-DOS extender for devs to finally move away from Assembly in mass.

              1. flohofwoe · · focus · HN ↗
                &gt; Nope, they were mostly written in Assembly.

                I was there, Gandalf ;)

                (and note how I specifically wrote &quot;dominant high level language&quot;, not &quot;dominant language&quot;, since assembly coding was indeed very relevant on those machines, for UI apps 100% assembly was quite rare though, and hybrid C&#x2F;ASM seems to have been more common).

                1. pjmlp · · focus · HN ↗
                  Dominant in which part of the planet?

                  In my part of the Iberian Penisula it was Turbo Pascal on PC and AMOS&#x2F;Blitz Basic on Amiga.

                  With lots of inline Assembly anyway.

                  1. jstimpfle · · focus · HN ↗
                    If id Software is any indication, apparently they wrote their games in C since their inception in 1990 with Commander Keen.
                    1. pjmlp · · focus · HN ↗
                      One tree doesn&#x27;t make a forest.
              2. aleph_minus_one · · focus · HN ↗
                &gt; Nope, they were mostly written in Assembly.

                It depends: for the classic 8 bit home computers, games were mostly written in assembly. Later DOS games were commonly either written in Pascal or C, but quite a bit off Assembler code was often used for the more performance-critical code sections.

                1. pjmlp · · focus · HN ↗
                  The &quot;quite a bit of Assembler&quot; is relevant.

                  I have seen code where folks used Pascal or C compilers as poor man&#x27;s macro assemblers, the &quot;quite a bit&quot; was rather large.

                  1. aleph_minus_one · · focus · HN ↗
                    As far as I know, this depended a lot on the individual game:

                    Games that had quite a bit of code that profited from the higher-level abstractions that C&#x2F;Pascal provided, such as

                    - resource management (including dynamic asset loading&#x2F;unloading)

                    - enemy AI

                    - pathfinding

                    - ...

                    of course typically contained a lot more C&#x2F;Pascal code than games that were more on the &quot;multimedia demo&quot; side with a simpler game logic.

        4. jjav · · focus · HN ↗
          &gt; UNIX was an extremely niche operating system until Linux won the data center

          UNIX was ubiquitous in the data center well before Linus even posted his first version of Linux on USENET.

          Everything ran on SunOS, HP-UX, IRIX, AIX, etc.

        5. ykonstant · · focus · HN ↗
          &gt; UNIX was an extremely niche operating system until Linux won the data center

          ?!? What a claim!

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.