size_t 与 ssize_t

In order to enhance the portability of the program, there is size_t, which is defined to facilitate the portability between systems. On different systems, the definition of size_t may be different.

It is defined as unsigned int on a 32-bit system, which means that it is a 32-bit unsigned integer (typedef unsigned int size_t) on a 32-bit system. It is defined as unsigned long on a 64-bit system, which means that it is a 64-bit unsigned integer (typedef unsigned long size_t) on a 64-bit system. size_t is generally used to represent a count, such as how many things are copied. For example, the result type of the sizeof operator is size_t, which is guaranteed to hold the size in bytes of the largest object created by the implementation. Its meaning is roughly "an unsigned integer type suitable for measuring the number of data items that can be held in memory". So, it is widely used in things like array subscripting and memory management functions.

The ssize_t data type is used to represent the size of the data block that can be read and written. It is similar to size_t, but must be signed. That is: it represents the type of signed size_t (typedef signed int ssize_t).



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326121486&siteId=291194637