Looking for counterexample: My C code never uses pointer casts, volatile, memcpy (etc.), unions, so it never violates strict aliasing rules.
-
-
Replying to @BRIAN_____
struct Foo { int x; float y; }; int main() { struct Foo data = Foo { 0 }; return (&data.x)[1]; }
1 reply 0 retweets 1 like -
Replying to @Gankro @BRIAN_____
I'd be willing to believe this is UB according to a different rule, though.
1 reply 0 retweets 0 likes -
Replying to @Gankro
I'd guess that it's UB to access memory beyond the end of (&x[0]) because there could be padding there.
1 reply 0 retweets 1 like -
Replying to @BRIAN_____
Eh yeah I didn't want to work too hard to avoid padding issues. I assume you can avoid that with newtypes of int?
1 reply 0 retweets 0 likes -
Replying to @Gankro @BRIAN_____
struct X{ a: int; } struct Y{ b: int }; struct Foo { struct X x; struct Y y; }; Can't possibly have padding?
1 reply 0 retweets 0 likes
I'm not so sure about that. Regardless, I think it makes sense to add a qualifier "assuming common-sense pointer math & indexing."
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.