The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: "G. Branden Robinson" <g.branden.robinson@gmail.com>
To: TUHS main list <tuhs@tuhs.org>
Subject: [TUHS] Re: Minimum Array Sizes in 16 bit C (was Maximum)
Date: Sat, 28 Sep 2024 13:01:38 -0500	[thread overview]
Message-ID: <20240928180138.aygrwqdwrvq3n6xt@illithid> (raw)
In-Reply-To: <20240928165812.4uyturluj4dsuwef@illithid>

[-- Attachment #1: Type: text/plain, Size: 3068 bytes --]

[self-follow-up]

At 2024-09-28T11:58:16-0500, G. Branden Robinson wrote:
> > malloc was in v7, before the C standard was written. The standard
> > spinelessly buckled to allow malloc(0) to return 0, as some
> > implementations gratuitously did.
> 
> What was the alternative?  There was no such thing as an exception, and
> if a pointer was an int and an int was as wide as a machine address,
> there'd be no way to indicate failure in-band, either.

While I'm making enemies of C advocates, let me just damn myself further
by suggesting an answer to my own question.

The obvious and correct thing to do was to have any standard library
function that could possibly fail return a structure type instead of a
scalar.  Such a type would have two components: the value of interest
when valid, and an error indicator.[1]

As John Belushi would have said at the time such design decisions were
being made, "but nooooooooo".  Returning a struct was an obviously
HORRIBLE idea.  My god, you might be stacking two ints instead of one.
That doubles the badness!  Oh, how we yearn for the days of the PDP-7,
when resources were so scarce that a system call didn't return
_anything_.  If it failed, the carry flag was set.  "One bit of return
value ought to be enough for anyone," as I hope Ken Thompson never said.

Expounders of Doug's tenet would, or should, have acknowledged that by
going to the library _at all_, they were giving up any O(1) guarantee,
and likely starting something O(n) or worse in time and/or space.  So
what's so awful about sticking on a piece of O(1) overhead?  In the
analysis of algorithms class lecture that the wizards slept through, it
was pointed out that only the highest-order term is retained.  Well, the
extra int was easy to see in memory and throw a hissy fit about, and I
suppose a hissy fit is exactly what happened.

Much better to use a global library symbol.  Call it "errno".  That's
sure to never cause anyone any problems with reentrancy or concurrency
whatsoever.  After all:

"...C offers only straightforward, single-thread control flow: tests,
loops, grouping, and subprograms, but not multiprogramming, parallel
operations, synchronization, or coroutines." (K&R 2e, p. 2)

It's grimly fascinating to me now to observe how many security
vulnerabilities and other disasters have arisen from the determination
of C's champions to apply it to all problems, and with especial fervor
to those that K&R explicitly acknowledged it was ill-suited for.

Real wizards, it seems, know only one spell, and it is tellingly
hammer-shaped.

Regards,
Branden

[1] Much later, we came to know this (in slightly cleaner form) as an
    "option type".  Rust advocates make a big, big deal of this.  Only
    a slightly bigger one than it deserves, but I perceive a replay of
    C's cultural history in the passion of Rust's advocates.  Or maybe
    something less edifying than passion accounts for this:

    https://fasterthanli.me/articles/the-rustconf-keynote-fiasco-explained

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-09-28 18:01 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-28 13:34 Douglas McIlroy
2024-09-28 16:58 ` G. Branden Robinson
2024-09-28 17:47   ` Luther Johnson
2024-09-28 17:52     ` Luther Johnson
2024-09-28 18:46       ` G. Branden Robinson
2024-09-28 22:08         ` Luther Johnson
2024-09-28 22:45           ` Luther Johnson
2024-09-28 22:50             ` Luther Johnson
2024-09-28 17:59   ` Bakul Shah via TUHS
2024-09-28 22:07     ` Douglas McIlroy
2024-09-28 23:05       ` Rob Pike
2024-09-28 23:30         ` Warner Losh
2024-09-29 10:06           ` Ralph Corderoy
2024-09-29 12:25             ` Warner Losh
2024-09-29 15:17               ` Ralph Corderoy
2024-09-30 12:15           ` Dan Cross
2024-09-28 18:01   ` G. Branden Robinson [this message]
2024-10-01 13:13     ` arnold
2024-10-01 13:32       ` Larry McVoy
2024-10-01 13:47         ` arnold
2024-10-01 14:01           ` Larry McVoy
2024-10-01 14:18             ` arnold
2024-10-01 14:25             ` Luther Johnson
2024-10-01 14:56               ` Dan Cross
2024-10-01 15:08                 ` Stuff Received
2024-10-01 15:20                 ` Larry McVoy
2024-10-01 15:38                   ` Peter Weinberger (温博格) via TUHS
2024-10-01 15:50                     ` ron minnich
2024-10-01 19:04                 ` arnold
2024-10-01 16:49           ` Paul Winalski
2024-10-01 15:44       ` Bakul Shah via TUHS
2024-10-01 19:07         ` arnold
2024-10-01 20:34           ` Rik Farrow
2024-10-02  0:55             ` Steffen Nurpmeso
2024-10-02  5:49             ` arnold
2024-10-02 20:42               ` Dan Cross
2024-10-02 21:54                 ` Marc Donner
2024-10-05 17:45                 ` arnold
2024-10-06 12:20                   ` Dan Cross
2024-10-06 12:29                     ` [TUHS] UREP code (was Re: Re: Minimum Array Sizes in 16 bit C (was Maximum)) arnold
2024-10-01 16:40       ` [TUHS] Re: Minimum Array Sizes in 16 bit C (was Maximum) Paul Winalski
2024-09-28 18:05   ` Larry McVoy
2024-09-30 15:49     ` Paul Winalski
2024-09-29 16:56 Douglas McIlroy
2024-09-29 20:29 ` Rob Pike
2024-09-29 21:13   ` Rik Farrow
2024-09-29 22:21   ` Rich Salz
2024-09-29 23:56     ` Rob Pike
2024-09-30  0:36       ` Larry McVoy
2024-09-30  0:55         ` Larry McVoy
2024-09-30  1:09         ` Luther Johnson
2024-09-30  1:37           ` Luther Johnson
2024-09-30  3:52             ` ron minnich
2024-10-01 12:43             ` arnold
2024-09-30 19:12   ` Steffen Nurpmeso
2024-09-30 20:03     ` Rich Salz
2024-09-30 21:15       ` Steffen Nurpmeso
2024-09-30 22:14       ` Bakul Shah via TUHS
2024-10-01  1:42         ` Alexis
2024-09-30 20:14     ` Rik Farrow
2024-09-30 22:00       ` Steffen Nurpmeso
2024-10-01 12:53       ` Dan Cross
2024-11-18 12:00         ` Anton Shepelev
2024-11-18 12:46           ` Luther Johnson
2024-11-18 14:05             ` Steve Nickolas
2024-11-18 15:00               ` Anton Shepelev
2024-11-23 22:29                 ` Alexander Schreiber
2024-11-18 14:55             ` Anton Shepelev
2024-11-18 16:52               ` G. Branden Robinson
2024-11-18 17:00                 ` Anton Shepelev
2024-11-18 18:56                 ` Luther Johnson
2024-11-22  1:53           ` Dan Cross
2024-11-22  2:55             ` Luther Johnson
2024-09-29 21:24 ` Ralph Corderoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240928180138.aygrwqdwrvq3n6xt@illithid \
    --to=g.branden.robinson@gmail.com \
    --cc=tuhs@tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).