How to Declare a 32-bit Integer in C

前端 未结 9 2237
日久生厌
日久生厌 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:36

    You need to include inttypes.h instead of stdint.h because stdint.h is not available on some platforms such as Solaris, and inttypes.h will include stdint.h for you on systems such as Linux. If you include inttypes.h then your code is more portable between Linux and Solaris.

    This link explains what I'm saying: HP link about inttypes.h

    And this link has a table showing why you don't want to use long or int if you have an intention of a certain number of bits being present in your data type. IBM link about portable data types

提交回复
热议问题