The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Re: Minimum Array Sizes in 16 bit C (was Maximum)
@ 2024-09-28 13:34 Douglas McIlroy
  2024-09-28 16:58 ` G. Branden Robinson
  0 siblings, 1 reply; 74+ messages in thread
From: Douglas McIlroy @ 2024-09-28 13:34 UTC (permalink / raw)
  To: TUHS main list

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

> C's refusal to specify dynamic memory allocation in the language runtime
> (as opposed to, eventually, the standard library)

This complaint overlooks one tenet of C: every operation in what you
call "language runtime" takes O(1) time. Dynamic memory allocation
is not such an operation.

Your hobbyhorse awakened one of mine.

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. I can't imagine that any program
ever actually wanted the feature. Now it's one more undefined
behavior that lurks in thousands of programs.

There are two arguments for malloc(0), Most importantly, it caters for
a limiting case for aggregates generated at runtime--an instance of
Kernighan's Law, "Do nothing gracefully". It also provides a way to
create a distinctive pointer to impart some meta-information, e.g.
"TBD" or "end of subgroup", distinct from the null pointer, which
merely denotes absence.

Doug

[-- Attachment #2: Type: text/html, Size: 1367 bytes --]

^ permalink raw reply	[flat|nested] 74+ messages in thread
* [TUHS] Re: Minimum Array Sizes in 16 bit C (was Maximum)
@ 2024-09-29 16:56 Douglas McIlroy
  2024-09-29 20:29 ` Rob Pike
  2024-09-29 21:24 ` Ralph Corderoy
  0 siblings, 2 replies; 74+ messages in thread
From: Douglas McIlroy @ 2024-09-29 16:56 UTC (permalink / raw)
  To: TUHS main list

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

>>> malloc(0) isn't undefined behaviour but implementation defined.
>>
>> In modern C there is no difference between those two concepts.

> Can you explain more about your view

There certainly is a difference, but in this case the practical
implications are the same: avoid malloc(0). malloc(0) lies at the high end
of a range of severity of concerns about implementation-definedness. At the
low end are things like the size of ints, which only affects applications
that may confront very large numbers. In the middle is the default
signedness of chars, which generally may be mitigated by explicit type
declarations.

For the size of ints, C offers guardrails like INT_MAX. There is no test to
discern what an error return from malloc(0) means.

Is there any other C construct that implementation-definedness renders
useless?

Doug

[-- Attachment #2: Type: text/html, Size: 1044 bytes --]

^ permalink raw reply	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2024-11-23 22:30 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-28 13:34 [TUHS] Re: Minimum Array Sizes in 16 bit C (was Maximum) 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
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

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).