Article View: comp.lang.c
Article #522Re: AVL tree insertion - programming exercise
From: Kaz Kylheku
Date: Sun, 18 Oct 2026 19:54
Date: Sun, 18 Oct 2026 19:54
40 lines
3005 bytes
3005 bytes
On 2026-10-18, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: > On 2026-10-18 10:42, Waldek Hebisch wrote: >>> [...] >> >> I read the above as: "can access part of object that fits in allocated >> space". That is important for structs and unions: you clearly do not >> want to allocate memory for biggest union variant. [...] > > Mind to explain that opinion? > > If I define a (C-)'union' type I definitely want to store anything > possible in those unions, changing the value to another type as > necessary. Sometimes you don't; you store one kind thing in the union and it stays that way for the life of the object. Perhaps there is a type field which indicaes the type of the object. If the smallest kind of object is 32 bytes, and the largest 512, you don't want to allocate 512 for the 32 variant. > Mind the 'sizeof' of a union is [at least?] the size > of its largest component. - If I 'malloc' a union I use that size. > In cases where I want to use just one [smaller] component-type of > a union I just allocate that specific type not the union-type. With the union type you can write the program with minimal pointer casts. If you know that "pobj" is a pointer to a string, as confirmed by pboj->u.base.type == OBJ_STR, you know you can access pboj->u.str.len (but not pboj->u.num.value). With transparent unions you can lose the "u." part. Can be (and has been) done with macros also. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID:
<20261018124834.267@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-mailReferences:
<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> <20261015163445.76@kylheku.com> <11b20os$3qlbh$1@paganini.bofh.team> <11b29gv$3pvda$3@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!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: Sun, 18 Oct 2026 19:54:23 -0000 (UTC) Organization: A noiseless patient Spider Lines: 40 Message-ID: <20261018124834.267@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> <20261015163445.76@kylheku.com> <11b20os$3qlbh$1@paganini.bofh.team> <11b29gv$3pvda$3@dont-email.me> Injection-Date: Sun, 18 Oct 2026 19:54:24 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1532874"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Mt9kIb7SSeI/rNJcVozNH9NiEqbhrKdg="; posting-host="ce2dcd5420b0135f78ece10ae38ec290" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:UP9m5NnZGWd4G3M7LziKsVxoxso= sha256:U4F4CGGiVUWfZyZAFXJmGbkyuD7cAhwbEuSS920xhuE= sha1:iKB+A2eGwSgsTL5C2gZItrN9tww= sha256:sau8tsQFwK6O0nkCmpqxZ1GPJ6laLKqmBAo2AqEGxdo=