int a[20], b[20], *p = a, i; if ((uintptr_t)(a + 20) == (uintptr_t)b) { b[5] = 1; for (i = 0; i < 40; i++) *p++ = 0; printf("%d\n", b[5]); }
-
-
Replying to @ch3root
gcc 4.9 and 5.2 with -O2 print 1 while the right result is 0. How much black magic do you need, to explain that the code is invalid C?
4 replies 0 retweets 0 likes -
Replying to @RichFelker
@RichFelker Isn't interchangability of equal values is one of the fundamentals of C?2 replies 0 retweets 0 likes -
Replying to @ch3root
@RichFelker@ch3root The code does have UB because you aren't allowed to access objects via a pointer to another.1 reply 0 retweets 0 likes -
Replying to @CopperheadOS
@RichFelker@ch3root The pointer used to access an object has to be derived from a pointer to that same object. Not a different one.2 replies 0 retweets 0 likes -
Replying to @CopperheadOS
@CopperheadSec@ch3root I don't see that language anywhere in the spec. Certainly cast to uintptr_t and back should be able to bypass.2 replies 0 retweets 0 likes -
Replying to @RichFelker
@CopperheadSec@ch3root If the values as uintptr_t are equal, casting back should yield a pointer which could access either object.1 reply 0 retweets 0 likes -
Replying to @RichFelker
@RichFelker@CopperheadSec This is wrong in practice. gcc tracks pointer's origin through casts to integers (and even floats).2 replies 0 retweets 0 likes
@ch3root @CopperheadSec This is almost surely an unsafe optimization that breaks conforming programs.
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.