3 ms·
"is undefined" there is rather hand-wave-y; really what that's supposed to say is that doing division by zero can do arbitrary things. Sure, looking at the ass
by dzaima 2y ago
"is undefined" there is rather hand-wave-y; really what that's supposed to say is that doing division by zero can do arbitrary things.
Sure, looking at the assembly it looks like the compiler has removed the 'if' branch, but, under "as if", it's equivalent to the compiler having rewritten 'a/b' to 'if (b==0) { printf("B\n"); } a/b', which strictly only modifies behavior at the UB.
And, while it may seem strange that UB results in such "copying" of code with minor alterations, that's not particularly rare at all. Take '(uint32_t)100 / someU32' on RISC-V, which'll result in -(uint64_t)1 on someU32==0 via the simple implementation of divu or divuw, despite that not being a valid uint32_t value, which'll result in significantly weird following behavior despite just being the most literal lowering.