On Fri, 31 Jan 2025, 06:50 The Cuthour via Gcc, <gcc@gcc.gnu.org> 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.
>
>
> To solve this problem, I propose the Linkable struct. The term
> Linkable struct is proposed in analogy to Linkable function.
> C language can be considered a language of Linkable functions.
> C language enhances the relinkability of functions by
> compromising the optimization of inline functions. C language
> does not need Linkable structs because structures are declared
> individually in C. Object-oriented languages need Linkable
> structs because classes (structures) are described as
> differences from their base classes.
>
> To achieve Linkable structs, I propose the Linkable constant.
> This mechanism ensures that certain constants are determined
> at link time and is realized by extending the ELF format. The
> offsets of structure members are defined in a distributed
> manner across object files using these constants, with their
> values resolved at link time. The information for calculating
> these constants is ideally stored in each object file in
> Reverse Polish Notation (RPN) for each symbol. The Linkable
> constant is also a compromise concerning the optimization of
> inline access to structure members.
>

It also means that sizeof(Pix) is no longer a constant expression, which
breaks the rules of the C++ language.

Imagine that Pix.cc contains:

static_assert(sizeof (Pix) <= 12);

The assertion passes when you compile it, but becomes invalid if you don't
recompile after changing Vec.h

This is not feasible.



>
>

Reply via email to