Article View: comp.lang.c
Article #378Re: AVL tree insertion - programming exercise
From: David Brown
Date: Wed, 14 Oct 2026 07:43
Date: Wed, 14 Oct 2026 07:43
101 lines
5606 bytes
5606 bytes
On 14/10/2026 06:13, Keith Thompson wrote:
> cross@spitfire.i.gajendra.net (Dan Cross) writes:
>> In article <86v775h9o2.fsf@linuxsc.com>,
>> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>> cross@spitfire.i.gajendra.net (Dan Cross) writes:
> [...]
>>>> I don't think this is true anymore, as of C23. Here's the
>>>> relevant text from n3220, sec 7.24.3, describing the return
>>>> value from `malloc` et al:
>>>>
>>>> |The pointer returned if the allocation succeeds is suitably
>>>> |aligned so that it may be assigned to a pointer to any type of
>>>> |object with a fundamental alignment requirement and size less
>>>> |than or equal to the size requested.
>>>>
>>>> This sentence is somewhat ambiguous because it's unclear whether
>>>> the "less than or equal to the size requested" criteria applies
>>>> to both the pointer type's size _and_ fundamental alignment
>>>> requirement, or _just_ the size, [...]
>>>
>>> It's poorly constructed but in English it has only one
>>> grammatical parse.
>>
>> Nope. Not even close.
>
> I think Tim is right about there being only one grammatical parse.
>
> I'll try to use indentation to indicate (imperfectly) how I parse it:
>
> The pointer returned if the allocation succeeds
> is suitably aligned so that
> it may be assigned to a pointer to any type of object
> with
> a fundamental alignment requirement
> andΒ·
> size less than or equal to the size requested.
>
> So "a fundamental alignment requirement" and "size less than or equal
> to the size requested" are parallel requirements, both applying to
> the type of the pointed-to object.
>
> I do see a problem with the size requirement being *under* the
> "suitably aligned" requirement. It wrongly implies that satisfying
> the size requirement contributes to the "suitably aligned" requirement.
> But that's not an ambiguous parse.
>
> Do you see a different way to parse the sentence?
>
I do. "Operators" in English do not have the same clearly defined
grammar rules as operators in C :
The pointer returned if the allocation succeeds
is suitably aligned so that
it may be assigned to a pointer to any type of object
with
a fundamental alignment requirement
and
size
less than or equal to the size requested.
equivalent to :
The pointer returned if the allocation succeeds
is suitably aligned so that
it may be assigned to a pointer to any type of object
with
a fundamental alignment requirement
less than or equal to the size requested.
and
size
less than or equal to the size requested.
If you consider "fundamental alignment requirement" as evaluating to a
number - the result of "alignas" - then I think this parse is also
possible. I would even go as far as to say this was the intended
parsing, because the parsing you gave above would mean the paragraph
only applies to "objects with a fundamental alignment requirement" - and
all complete object types have alignment requirements.
Let us suppose a hypothetical implementation where CHAR_BIT == 8,
sizeof(int) == 4, and alignof(int) == 8.
What guarantees do you have for "void * p = malloc(4);" ?
With your parsing, "p" would be correctly aligned for an int - the
alignment of the type "int" is not relevant to whether the "p" is
correctly aligned or not, only the size of "int" matters.
With the second parsing, "p" may not be correctly aligned for an int -
it is only guaranteed to be aligned for types with alignment
requirements of 4 or less.
That second parsing seems to result in a more logical and consistent
conclusion. But the first parsing seems more reasonable when reading it.
(I do not think any of this will make a difference in practice.)
Technical Details
Message-ID:
<11anbq5$16fmd$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<86ece2kppv.fsf@linuxsc.com> <11al4mu$fqtl$1@kst.eternal-september.org> <11ali2e$pi$1@reader2.panix.com> <86v775h9o2.fsf@linuxsc.com> <11am74c$54g$1@reader2.panix.com> <11amvh2$14pou$3@kst.eternal-september.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: AVL tree insertion - programming exercise Date: Wed, 14 Oct 2026 09:43:01 +0200 Organization: A noiseless patient Spider Lines: 101 Message-ID: <11anbq5$16fmd$1@dont-email.me> References: <86ece2kppv.fsf@linuxsc.com> <11al4mu$fqtl$1@kst.eternal-september.org> <11ali2e$pi$1@reader2.panix.com> <86v775h9o2.fsf@linuxsc.com> <11am74c$54g$1@reader2.panix.com> <11amvh2$14pou$3@kst.eternal-september.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Wed, 14 Oct 2026 07:43:02 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1261261"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zyzpoD5YYcL8B6be3w4uEaRJExxF3Iy4="; posting-host="8e9eb425ce63e0416e038808cc017c1f" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:iiuq8EBshhzdMBQul2hUFt3W1/E= sha256:b5XFA7ZDqs2BaDjo6e05BQUwPgnDf4v1djiERpzNfKc= sha1:zxpCuUifHuk9Jv1NQvPfVi495mY= sha256:RKMqv9TVuP2TrBgLxX96ON23kdXn/1diT2Tfw7M+IxY= In-Reply-To: <11amvh2$14pou$3@kst.eternal-september.org> Content-Language: en-GB, nb-NO