News for hackers. Stuff that matters.
Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector by groestl on Sunday January 21, 2024 @12:49PM (#39080705)
> Wait, so you're saying that code that subtracts an offset from a child node to get to a parent node is clearer and less complex than alternatives?

Parent made me laugh out loud on this.

Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector by jstimpfle on Sunday January 21, 2024 @12:58PM (#39080805)
I hope you've stopped laughing and can read and understand my answer.
Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector by groestl on Sunday January 21, 2024 @01:14PM (#39080998)
Please, I did not want to offend you personally. It just took me by surprise. I understand your points, even though I'm with your direct reply, all things considered.
Re:Boehm-Demers-Weiser conservative C/C++ Garbage Collector by jstimpfle on Sunday January 21, 2024 @05:35PM (#39083790)
The address offset subtraction thing specifically is used quite a bit in the Linux kernel for example. It allows to combine abstract code with concrete data. For example they define a red-black tree as a graph of just plain nodes. These nodes are totally abstract, they contain only node pointers but no useful data. The code is totally abstract, no need to instanciate anything a dozen times with different offsets and such. You simply wrap the abstract nodes with whatever concrete useful data you fancy.

The same approach works for lists and a variety of other data structures.

You can get from the abstract link node to the containing struct with a macro: CONTAINER_OF(ptr, containertype, membername). It's easy to use and unlikely to get it wrong.