🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #400

Re: AVL tree insertion - programming exercise

#400
From: Dan Cross
Date: Wed, 14 Oct 2026 20:11
84 lines
4736 bytes
In article <11anbq5$16fmd$1@dont-email.me>,
David Brown  <david.brown@hesbynett.no> wrote:
>On 14/10/2026 06:13, Keith Thompson wrote:
>> [snip]
>> 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.

Indeed.  And in fact, I found some direct evidence for exactly
this interpretation (the one I claimed was correct).  Draft 3054
(https://open-std.org/JTC1/SC22/WG14/www/docs/n3054.pdf)
includes this in the abstract:

|The following documents, for all intents and purposes, have
|been applied to this draft from before and during the October
|2019 Meeting: 
| ... (on down to the 6th from the top on the second page):
| - N2293 Alignment requirements for memory management functions

In turn, N2293 goes into detail about the change, the motivation
and the present wording in C23; specifically, it is clear that
they mean for the requested allocation size to factor in the
fundamental alignment requirement of the pointed-to type.  The
Summary section reads:

|The alignment requirements of `malloc`, `calloc`, and `realloc`
|are somewhat confusingly phrased, in a way that affects small
|allocations (sizes less than `_Alignof(max_align_t))`.  Some
|readers (and implementations) interpret them to demand
|`_Alignof(max_align_t)`-alignment even for allocation sizes
|that could not hold an object with that alignment.  We call
|this the "strong-alignment" reading.  Other readers (and
|implementations) interpret them as requiring the returned
|memory to be aligned only enough to accommodate those types
|that could inhabit the returned memory.  In particular, since
|`sizeof(T) >= _Alignof(T)` for all portably defined types `T`,
|allocations with sizes smaller than `_Alignof(max_align_t)`
|need only be aligned to the largest power of two less than or
|equal to the requested size.  We call this the "weak-alignment"
|reading.
|
|Many implementations only provide weak-alignment guarantees,
|and some cases these guarantees are important in conserving
|both CPU and memory.  Therefore, we propose clarifying the
|wording such that the weak-alignment implementation is
|unambiguously allowed.  Strong-alignment implementations remain
|correct, and may document the guarantee as an extension.
(https://www.open-std.org/JTC1/SC22/WG14/www/docs/n2293.htm)

I don't think we can get much more definitive than that.

	- Dan C.
Technical Details
Message-ID: <11aonlg$bhk$1@reader2.panix.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
References: <86ece2kppv.fsf@linuxsc.com> <11am74c$54g$1@reader2.panix.com> <11amvh2$14pou$3@kst.eternal-september.org> <11anbq5$16fmd$1@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
From: cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups: comp.lang.c
Subject: Re: AVL tree insertion - programming exercise
Date: Wed, 14 Oct 2026 20:11:28 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <11aonlg$bhk$1@reader2.panix.com>
References: <86ece2kppv.fsf@linuxsc.com> <11am74c$54g$1@reader2.panix.com> <11amvh2$14pou$3@kst.eternal-september.org> <11anbq5$16fmd$1@dont-email.me>
Injection-Date: Wed, 14 Oct 2026 20:11:28 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
	logging-data="11828"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)