News for hackers. Stuff that matters.
Re:Inheritance was invented as a performance hack by astrobe_ on Thursday May 08, 2025 @03:38AM (#43923986)
I found myself in a situation where I had to reinvent data structures from scratch in an assembly-like language: "properties" or "fields" are just offsets relative to a pointer (runtime) or an address (compile-time).

The need to extend a data structure to add more fields comes almost immediately. Think: something like the C "hack" of embedding the "base" structure as the first field of the "derived" structure:

   struct t_derived
   {
       struct t_base base;
       int extra_data;
   };
Then you can pass a derived_t instead of base_t with some type casting and caveats. This is "legal" in C because the standard guarantees that base has offset 0.

Of course our "extra_data" could be a structure, but although it would look like "A+B" it is actually a concatenation.

There are no comments on this comment yet.