Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Isn't that beauty ? (no it's not)
Date: Mon, 23 Mar 2026 21:23:47 -0700
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <86ecl94zzg.fsf@linuxsc.com>
References: <10otm7r$1ntrg$1@raubtier-asyl.eternal-september.org> <10ougtt$21vgj$1@dont-email.me> <10ouhm6$22rm2$1@raubtier-asyl.eternal-september.org> <10ouje5$21vgj$5@dont-email.me> <10oul1g$241b4$1@raubtier-asyl.eternal-september.org> <10ov73a$2bugo$3@dont-email.me> <10p03uu$2nho7$1@dont-email.me> <10p07kn$2pg89$1@dont-email.me> <%jVsR.22274$_l2.6511@fx40.iad> <8634207ssj.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Tue, 24 Mar 2026 04:23:53 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="49275a8acb80bae5953bf00d88b0bbe4"; logging-data="774486"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1879RQCVM04pX6yQ9EmQpDnYEOeeigQJy0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Hj40FFyH7Stt+cJcQkObgbKJZ1o= sha1:MZK8PfgIp8GKNY9gLnOAZ3SF6q4=
Xref: csiph.com comp.lang.c:397170
scott@slp53.sl.home (Scott Lurndal) writes:
> Tim Rentsch writes:
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>> DFS writes:
[...]
>>>>> Why are you allowed to malloc size 0?
>>>>
>>>> "If the size of the space requested is 0, the behavior is
>>>> implementation-defined: either a null pointer shall be returned,
>>>> or the behavior shall be as if the size were some non-zero value,
>>>> except that the behavior is undefined if the returned pointer is
>>>> used to access an object."
>>>>
>>>> https://pubs.opengroup.org/onlinepubs/9799919799/functions/malloc.html
>>>
>>> IIRC, this caveat was added due to differences in the malloc(3)
>>> implementations for System V Unix and BSD Unix.
>>
>> That sounds right, except I might say "put in" rather than "added"
>> since as best I can determine that allowance was present in the
>> earliest drafts of the C standard and POSIX discussions.
>>
>> Note that malloc() is not mentioned in K&R, and apparently was
>> added to AT&T Unix in Unix V7. The timing on that was about the
>> same time as the first BSD Unix.
>
> Right. K&R 1st Ed. defined a 'morecore' function based on sbrk.
Ahh, I missed that. So it does.
> K&R 2nd Ed. (ANSI) added malloc.
Presumably malloc() was included in the early standard efforts
well before K&R 2, which came out in 1988 IIRC. The early
standardization work started in 1982 or 1983 IIANM, and malloc()
had already been available since 1979, as both AT&T Unix V7 and
BSD Unix were available at that time.