logoalt Hacker News

Chinjuttoday at 1:39 PM1 replyview on HN

How is undefined behavior necessary for this transformation?


Replies

jstimpfletoday at 2:15 PM

IIRC computation of the address is done by computing offset from base pointer as a multiplication in (32-bit) int, (like p + (i * sizeof (Foo)). The right term might overflow, but due to signed overflow being UB, the compiler is able to assume that it does not, so the transformation to do the arithmetic entirely in (64-bit) pointer space is valid.

show 1 reply