Poll: does this violate strict aliasing? struct b { int x; } S; int *p = (int*)&S; *p = 1;
If p "points to" x, and *p has type matching the effective type of x, then p meets conditions for * operator to be well-defined on it.
-
-
Ok I can't produce a counter-example where a compiler will optimize more aggressively than this interpretation allows, so we'll use this.
-
For reference, I think GCC devs claim it's &p->a that's wrong if one passes the address of an int or a struct s2 https://godbolt.org/g/0iLBjc
-
6.7.2.1 ¶15 ends with "and vice versa", i.e. if you have a ptr to initial member, it's valid to cast to struct ptr & access the struct.
-
(But only if the pointer actually points to the initial member of a struct of that type, not to a different struct type or no struct at all)
-
Yes, that seems the right way to look at it.
-
I'm worried about dynamic allocation though: https://godbolt.org/g/M3glwK One can hardly warn at the time p1, q1 are computed.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.