🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #436

Re: AVL tree insertion - programming exercise

#436
From: Kaz Kylheku
Date: Thu, 15 Oct 2026 23:51
75 lines
4643 bytes
On 2026-10-15, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> cross@spitfire.i.gajendra.net (Dan Cross) writes:
>> In article <11ap0fo$1t8gq$2@kst.eternal-september.org>,
>> Keith Thompson  <Keith.S.Thompson+u@gmail.com> wrote:
>>>cross@spitfire.i.gajendra.net (Dan Cross) writes:
>>>> In article <11amvh2$14pou$3@kst.eternal-september.org>,
>>>> Keith Thompson  <Keith.S.Thompson+u@gmail.com> 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.
>>>>
>>>> That is one of the two reasonable interpretations.  The other is
>>>> that the requirements placed on size and fundamental alignment
>>>> of the pointer type are cumulative and dependent on the size of
>>>> the allocation.  If so, then nothing in the C standard prevents
>>>> an implementation from from returning a pointer aligned to
>>>> `alignof(char)` for `malloc(1)`.
>>>
>>>I do see the parsing ambiguity now.
>>>
>>>I believe that's consistent with the way I parsed it.  A successful
>>>malloc(1) returns a value that can be assigned to a pointer of type
>>>char*, which points to the object type "char", which does have (a
>>>fundamental alignment requirement) and (a size less than or equal
>>>to the size requested).
>>
>> Right, but I think it's a bit deeper than that.
>>
>> Somewhat informally, the C17 wording could be read as requiring
>> that the pointer returned from `malloc` must be suitable for
>> assignment to any pointer to a type with `alignof(max_align_t)`
>> regardless of the requested size, which might be smaller.  N2293
>> calls this the, '"strong-alignment" reading.'
>
> The C17 wording is:
>
>     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 then used to access such an
>     object or an array of such objects in the space allocated (until the
>     space is explicitly deallocated).

I suspect that this should be read as "any type of object which can
fit into the requested size".

> I don't see any other way to interpret that.

It can be interpreted a a defect.

Note that in a single sentence, the requirement is being given that:

- the pointer from a successful allocation is aligned for any object

- the pointer can be used to access such an object ... in the space
  allocated

From that we can infer that "any type" cannot literally be any type
Because if we have a successful malloc(1) and we choose "long long" to
be any type, the literally interpreted requirements are that we can
convert the pointer to "long long *" and use the resulting pointer for
access. That requires a malloc(1) to be adjusted to malloc(sizeof (long
long)); the requirement goes beyond alignment.

It must be that "any type" means "any type that can be
stored in the space allocated".

Then the whole thing makes sense; yes, the pointer can be converted
to that type and used to access such an object in the space allocated,
because it fits.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID: <20261015163445.76@kylheku.com>
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
References: <86ece2kppv.fsf@linuxsc.com> <11amvh2$14pou$3@kst.eternal-september.org> <11ao2mr$4l9$1@reader2.panix.com> <11ap0fo$1t8gq$2@kst.eternal-september.org> <11aqnp0$sb$1@reader2.panix.com> <11arlj9$2q39c$1@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: Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: AVL tree insertion - programming exercise
Date: Thu, 15 Oct 2026 23:51:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <20261015163445.76@kylheku.com>
References: <86ece2kppv.fsf@linuxsc.com>
 <11amvh2$14pou$3@kst.eternal-september.org>
 <11ao2mr$4l9$1@reader2.panix.com>
 <11ap0fo$1t8gq$2@kst.eternal-september.org>
 <11aqnp0$sb$1@reader2.panix.com>
 <11arlj9$2q39c$1@kst.eternal-september.org>
Injection-Date: Thu, 15 Oct 2026 23:51:19 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3006556"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19missbCCupx3/rw7sylXiBnK5qhUztH+o="; posting-host="345be0a34e746410ec6618de9e0a9562"
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:kXMTGxC4C2oyKE28Idw4+WwV6JQ= sha256:fUuX7A/iCJuqOiTY992ldVchvtM2uuZa96PAKj/1rVs=
	sha1:On9qqF9BaEdTpc9jtgL8dqzcVms= sha256:463GL7sZDKzF8vYvMv4CRs+0OBCivX43YTEtykz09E4=