How to Declare a 32-bit Integer in C

前端 未结 9 2261
日久生厌
日久生厌 2020-12-05 03:53

What\'s the best way to declare an integer type which is always 4 byte on any platforms? I don\'t worry about certain device or old machines which has 16-bit int

9条回答
  •  醉话见心
    2020-12-05 04:25

    Corey's answer is correct for "best", in my opinion, but a simple "int" will also work in practice (given that you're ignoring systems with 16-bit int). At this point, so much code depends on int being 32-bit that system vendors aren't going to change it.

    (See also why long is 32-bit on lots of 64-bit systems and why we have "long long".)

    One of the benefits of using int32_t, though, is that you're not perpetuating this problem!

提交回复
热议问题