Poll: does this violate strict aliasing? struct b { int x; } S; int *p = (int*)&S; *p = 1;
-
-
Found in < 1 min knowing the right phrase to grep for: "initial member".
-
I'm not sure what this paragraph means by “points to its initial member”. One could argue that when x is an int *, (void**)&x “points to” x…
-
that does not mean that you are allowed to dereference it to access a, only that if you convert both to void* and compare them, they're ==
-
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)
- 2 more replies
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.