The C language defines the following integer types (unsigned is not listed): Char short intlonglong long, but the C language does not specify the relationship between them: sizeof (char) <= sizeof (short) <= sizeof (INT) <= sizeof (long) modern Unix systems are either 32-bit or 64-bit (there may be 128-bit in the future ), the experience I have summarized is: sizeof (char) = 1 sizeof (short) = 2 sizeof (INT) = 4 sizeof (long) = 4 (32-bit) or 8 (64-bit) sizeof (long) = 8 in the Unix system I used (GNU Linux, Sun Solaris, IBM AIX, HP-UX, Mac OSX) this is the case. As long as it is not embedded development, most of them are the case above. Of course, there is a better way to define a fixed-length integer under POSIX, in stdint. h contains the following types: fixed-length INTEGER: int8_t/Bytes/uint16_tint32_t/uint32_tint64_t/uint64_t. The prefix U indicates unsigned.
Specify the minimum length of integer: int_lease8_t/extra/uint_fast32_tint_fast64_t/uint_fast32_tlease integer to ensure sizeof (int_lease [x] _ T) * 8> = [X]. For example, in some hardware, the hardware may not support direct storage of 16-bit integers, but only 32-bit integers. If int16_t is used, the compiler needs to generate special code for simulation. At this time, using the Lease Type can reduce unnecessary code generation. Fast integer and lease are similar, but they are used to optimize the speed. Generally, an integer with the same CPU processing length as its word length will be faster (theoretically ), if word is 32-bit, int_fast8_t and int_fast16_t are defined as int_fast32_t. If you do not want to port the program to special hardware, the lease and fast integer types are generally not required.
Integer With the same length as the pointer: intptr_t/uintptr_t should be noted if you want to convert the pointer to an int. If you want to write a portable C code, there must be no pointer-to-Int or Int-to-pointer conversion. In 32-bit cases, the 64-bit system will be overwhelmed. The length of the above two types of vehicles is the same as that of the pointer, and the conversion in that direction is safe. (Based on experience, you can use long)
Integer With the maximum length: intmax_t/uintmax_t indicates the integer with the maximum length that the system can process, which is usually 64-bit. No 128-bit system has been encountered yet.
Unicode-related types:
Wchar_t/wint_t
Because the Unicode Standard has many versions, the character set in earlier versions can be expressed with uint16_t. Later, as more and more characters are added, they must be represented by uint32_t.
Wint_t indicates all Unicode characters and extended character sets. For details, refer to the UTF16 encoding method. (I guess it is like this: in some systems, wchar_t is UTF16 encoding, and wint_t is UTF32 encoding)