Article View: comp.lang.c
Article #440Re: AVL tree insertion - programming exercise
From: Keith Thompson
Date: Fri, 16 Oct 2026 04:34
Date: Fri, 16 Oct 2026 04:34
69 lines
4511 bytes
4511 bytes
cross@spitfire.i.gajendra.net (Dan Cross) writes:
[Snip stuff I agree with]
> Right. The only reason I wanted to write it that way was to
> drive that point home; in the "strong-alignment" reading, for
> small allocations, the alignment of the address the pointer
> returned from `malloc` refers to is totally decoupled from the
> requested size: `sizeof(char[3])` is three, which reflects the
> fundamental alignment requirement of `char[3]` being 1; because
> `malloc` doesn't know whether the resulting allocation will be
> used to store something with a fundamental alignment criteria of
> two or not (assuming such a type exists in the implementation),
> it must return a pointer to an address that is at least aligned
> to an even boundary. In any event, whether `malloc` must return
> something with stronger alignment, or merely can at its own
> convenience, is the interesting high order bit here.
Just to avoid any misunderstanding, you refer to "the fundamental
alignment requirement of `char[3]` being 1".
The phrase "fundamental alignment requirement" might be misleading.
It could imply to someone unfamiliar with the terminology that
char[3] could have a fundamental alignment requirement and a
differing non-fundamental alignment requirement. (I had thought
the term "fundamental alignment" was new in C23, but it was added
in C11.)
It's possible that I'm the only one who thought this might be
confusing. If so, ignore this.
To over-explain: Each object type has an alignment, which is an integer
value.
A *fundamental alignment* is a valid alignment less than or equal to
alignof(max_align_t).
An *extended alignment* is represented by an alignment greater than
alignof(max_align_t).
As far as the language is concerned `char[3]` has an alignment of
1, and that alignment happens to be a fundamental alignment. (A
compiler might allocate standalone `char[3]` objects at a stricter
alignment, but the standard doesn't address that; compilers can
over-align anything they like.)
Which might be part of the confusion about the malloc() wording in C23.
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.
I read the phrase "with a fundamental alignment requirement" as a
predicate. A type has a fundamental alignment requirement or it
doesn't.
The alternative reading is "with a fundamental alignment requirement
(and size) less than or equal to the size requested", which says that
the alignment requirement (a) is fundamental *and* (b) is less than or
equal to the size requested. I think that's a rather strained
interpretation -- and I can't think of any cases where the distinction
between the two readings of the C23 wording could be significant, given
that an object type can't have an alignment bigger than its size.
[Snip more stuff I agree with]
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */
Technical Details
Message-ID:
<11as9gl$2vtou$1@kst.eternal-september.org>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!kst.eternal-september.org!.POSTED!not-for-mailReferences:
<86ece2kppv.fsf@linuxsc.com> <11ap0fo$1t8gq$2@kst.eternal-september.org> <11aqnp0$sb$1@reader2.panix.com> <11arlj9$2q39c$1@kst.eternal-september.org> <11as4h9$7ht$1@reader2.panix.com>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!kst.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: AVL tree insertion - programming exercise Date: Thu, 15 Oct 2026 21:34:29 -0700 Organization: None to speak of Lines: 69 Message-ID: <11as9gl$2vtou$1@kst.eternal-september.org> References: <86ece2kppv.fsf@linuxsc.com> <11ap0fo$1t8gq$2@kst.eternal-september.org> <11aqnp0$sb$1@reader2.panix.com> <11arlj9$2q39c$1@kst.eternal-september.org> <11as4h9$7ht$1@reader2.panix.com> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Fri, 16 Oct 2026 04:34:30 +0000 (UTC) Injection-Info: kst.eternal-september.org; logging-data="3143454"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dTnjWSD20CEjgHCp+MmsH"; posting-host="cf7ed1e612447f7784dc01a34361c57c" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:GEIiMJGZdwjjhlfEj9jsCdEN1SU= sha256:IZMuYJ5nY+9MFLo5pILoHMxerMM3I1TKqUac34bTsPo= sha1:rHeGejBzP91JEzIQMU5JekXNZPE= sha256:GpbXYI4OunQISEl3V+McnlLZzOUQDImhJMkkZqyKrIc=