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.

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.

9 more comments...

No posts

Ready for more?