Discussion about this post

User's avatar
Lukas's avatar

The optimization can also be done for unsigned integers, it just has to be done slightly differently. https://ideone.com/EBwo8e

So undefined behavior isn't really enabling much more of an optimization here. It's just that the compiler misses this optimization for unsigned ints.

Expand full comment
Yacob Cohen-Arazi's avatar

so why the compiler cannot use the more optimized, no loop method? unsigned has a well defined wrap around outcome.

Expand full comment
9 more comments...

No posts