On 22.01.26 20:46, Andres Freund wrote:
However, you qualified your answer with "to a different pointer-to-struct",
but afaict the rules would be the same if the "initial member" of two
different structs were a struct.


There's also C23's §6.5 7):
   An object shall have its stored value accessed only by an lvalue expression 
that has one of
   the following types:
   ...
   — an aggregate or union type that includes one of the aforementioned types 
among its
   members (including, recursively, a member of a subaggregate or contained 
union), or

which afaict means that if we *can* cast between different equivalent structs,
as long as they have the same initial sequence?

I think what this means is that if you have

typedef struct Append
{
    Plan        plan;
    ...
}

and you have an object of type Plan, then you can access that object via a pointer of type Append.

Now that I see this again, this is the opposite the direction of what we would need (have object of type Append, access via pointer to Plan, or pointer to Node). Also note that it doesn't require that member to be the first member. So this consideration seems to be unrelated to what we are looking for.



Reply via email to