https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86259

--- Comment #15 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #14)
> > You say that
> > 
> >  struct { int a; int b; } s, s2;
> >  memcpy (&s2.a, &s.a, sizeof (s));
> > 
> > is invalid, aka not copying the whole structure since you pass in a
> > pointer to s2.a rather than s2?
> 
> Yes.

Let's give the struct a name and introduce some casts

typedef struct { int a; int b; } S;
S s, s2;
memcpy ((S*)&s2.a, (S*)&s.a, sizeof(s));

The standard makes it valid to convert &s.a to S* and makes it equivalent to
&s. Because of the call to memcpy, it gets converted to void* afterwards. So
you are saying that (void*)&s.a is not the same as (void*)(S*)&s.a (note that
no arithmetic is involved at this point). This looks like it is going to cause
trouble...

Reply via email to