In C, why is “signed int” faster than “unsigned int”?

后端 未结 4 1917
隐瞒了意图╮
隐瞒了意图╮ 2020-12-25 12:05

In C, why is signed int faster than unsigned int? True, I know that this has been asked and answered multiple times on this website (links below).

4条回答
  •  执笔经年
    2020-12-25 12:42

    Because signed integer overflow is undefined, the compiler can make a lot of assumptions and optimizations on code involving signed integers. Unsigned integer overflow is defined to wrap around, so the compiler won't be able to optimize as much. See also http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html#signed_overflow and http://www.airs.com/blog/archives/120.

提交回复
热议问题