On Fri, 2025-01-31 at 15:49 +0900, The Cuthour via Gcc wrote:
> Suppose we have the following two classes:
> 
> === Vec.h ===
> class Vec {
>      int x, y, z;
> };
> === end Vec.h ===
> 
> === Pix.h ===
> class Pix: Vec {
>      int r, g, b;
> };
> === end Pix.h ===
> 
> If we add or remove a member variable in class Vec, it requires
> recompiling not only Vec.cc but also Pix.cc. I believe this is
> a problem. Pix.o should be relinkable.

In real world software, such small classes are unlikely to be put into their
own .cc files but tend to be header-only libraries.

struct image
{
  vec2 pos[2];
  std::vector<vec3> pixels;
};

Now if any of those structs are modified, members added or removed, it would
require recompilation of the whole code that uses it.  This is because the
memory offsets to access the fields change and might fall out of the
displacement range of the processor's instructions.  So to support your idea
the compiler would need to generate worst-case code to access any arbitrary
offsets which will drag down code performance.  The linker would need added
optimizing steps to undo this ... it sounds like a can of worms.

Best regards,
Oleg Endo

Reply via email to