Poll: does this violate strict aliasing? struct b { int x; } S; int *p = (int*)&S; *p = 1;
-
-
-
Replying to @RichFelker
Found in < 1 min knowing the right phrase to grep for: "initial member".
2 replies 1 retweet 3 likes -
Replying to @RichFelker
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…
1 reply 0 retweets 0 likes -
Replying to @volatile_void @RichFelker
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 ==
1 reply 0 retweets 0 likes -
Replying to @volatile_void
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.
1 reply 0 retweets 0 likes -
Replying to @RichFelker
Ok I can't produce a counter-example where a compiler will optimize more aggressively than this interpretation allows, so we'll use this.
1 reply 0 retweets 0 likes -
Replying to @volatile_void @RichFelker
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
1 reply 0 retweets 0 likes -
Replying to @volatile_void
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.
1 reply 0 retweets 0 likes
(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)
-
-
-
Replying to @volatile_void @RichFelker
I'm worried about dynamic allocation though: https://godbolt.org/g/M3glwK One can hardly warn at the time p1, q1 are computed.
0 replies 0 retweets 0 likes
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.