Article View: comp.lang.c
Article #338Re: AVL tree insertion - programming exercise
From: David Brown
Date: Tue, 13 Oct 2026 15:39
Date: Tue, 13 Oct 2026 15:39
51 lines
3551 bytes
3551 bytes
On 13/10/2026 17:17, Dan Cross wrote: > In article <11al4mu$fqtl$1@kst.eternal-september.org>, > Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote: >> David Brown <david.brown@hesbynett.no> writes: >>> On 13/10/2026 10:38, chine.bleu wrote: >>>> Tim Rentsch wrote: >>>>> sons[2] array. These links are basically pointers, but held >>>>> as uintptr_t so they can take one of the bits to mean "tall", >>>>> which means taller than the other subtree of the node. The >>>>> tree structure should maintain an invariant that at most one >>>> Memory is cheap. >>> >>> Not any more! >>> >>>> Do not encode tags into low bits of an address unless you really >>>> know what your doing. >>> >>> Agreed, as a principle. >>> >>>> As a precaution check the return address of malloc >>>> p = malloc(m); >>>> if ((uintptr_t)p)&1!=0) abort(); >>> >>> malloc always returns an address with suitable alignment for any >>> fundamental alignment on the target. > > 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, but I believe that it is the > former (that is, the "and" applies the size requirement to both > alignment and returned size). Thus, a conforming implementation > of `malloc(1)` could return a pointer that is `alignof(char)`, > but not `alignof(int)`. > Your interpretation seems sound to me. (I looked at the C11 standards when I made my earlier post - it had not occurred to me that C23 might have changed the wording here. The change is not mentioned in the change history, as far as I can see.)
Technical Details
Message-ID:
<11aljb2$j7bi$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> <11akqm4$c6h9$1@dont-email.me> <11akuf1$bq6c$1@dont-email.me> <11al4mu$fqtl$1@kst.eternal-september.org> <11ali2e$pi$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!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: AVL tree insertion - programming exercise Date: Tue, 13 Oct 2026 17:39:14 +0200 Organization: A noiseless patient Spider Lines: 51 Message-ID: <11aljb2$j7bi$1@dont-email.me> References: <86ece2kppv.fsf@linuxsc.com> <11akqm4$c6h9$1@dont-email.me> <11akuf1$bq6c$1@dont-email.me> <11al4mu$fqtl$1@kst.eternal-september.org> <11ali2e$pi$1@reader2.panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 13 Oct 2026 15:39:14 +0000 (UTC) Injection-Info: dont-email.me; logging-data="630130"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Fi+arm7HenXPTlLX9ImVtjyPl6R9zG4Y="; posting-host="0453d936fb977b9ac4728f0f8db2cabc" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:AAHZO2NZMf+rv4uZxKY7RmNnlLk= sha256:N938X1LuIZK3lHH41Lueitx98Rmlsv0k/kDNPN5CPO8= sha1:xMgBI7OK5dblO6b3YK6VdhnWw2A= sha256:1WtqqgP35NFQ07DZYi0ddZXn8avVp/IZ9AcNzSv5bag= Content-Language: en-GB, nb-NO In-Reply-To: <11ali2e$pi$1@reader2.panix.com>