| From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
|---|---|
| To: | Andres Freund <andres(at)anarazel(dot)de> |
| Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Tatsuo Ishii <ishii(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org |
| Subject: | Re: warning: dereferencing type-punned pointer |
| Date: | 2026-01-23 08:20:29 |
| Message-ID: | 581db49e-2a12-4f89-8c3e-334ba5889ff7@eisentraut.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Anthonin Bonnefoy | 2026-01-23 08:21:53 | Re: Fix rounding method used to compute huge pages |
| Previous Message | Zsolt Parragi | 2026-01-23 08:08:47 | Re: Remove redundant initialization of smgr pointer for relcache |