ec429 said:
Why is this? If the two struct (say) types have been defined
identically, what optimisation can the compiler possibly make that'll
be valid for one but not the other?
What Kaz Kylheku said -- stores into one kind of struct can
be assumed not to affect members in a different kind of
struct, if the two structs involved are not both in a single
union object. Note that this latter condition can happen
even if both struct types are included in a union but one
of the actual struct objects is known not to be in a union.
For example, compiling (I haven't actually compiled this,
please excuse any minor mistakes):
struct foo { int x; ... };
struct bas { int x; ... };
union foobas { struct foo f; struct bas b; };
extern struct foo global_foo = { 1 };
int
mumble( union foobas *p, struct bas *q ){
global_foo.x = 7;
q->x = 13;
p->b.x = 14;
p->f.x = 15;
return global_foo.x;
}
the compiler is allowed to assume the function will return
the value 7, because none of the intermediate assignments
can affect global_foo.x. However, the three intermediate
assignments cannot be rearranged relative to each other,
because any one of them might affect the others.