Is using unsigned integer overflow good practice?

后端 未结 12 529
耶瑟儿~
耶瑟儿~ 2020-12-01 15:55

I was reading the C Standard the other day, and noticed that unlike signed integer overflow (which is undefined), unsigned integer overflow is well defined. I\'ve seen it us

12条回答
  •  既然无缘
    2020-12-01 16:58

    siukurnin makes a good point, that you need to know when overflows will occur. The easiest way to avoid the portability issue he described is to use the fixed-width integer types from stdint.h. uint32_t is an unsigned 32-bit integer on all platforms and OSes, and won't behave differently when compiled for a different system.

提交回复
热议问题