Linux ssize_t and size_t

Source: Internet
Author: User

Ssize_t is signed
Size_t,
Size_t is defined in the Standard C library and should be an unsigned int.
Socket_t:
The data type "socklen_t" and int should have the same length. otherwise, the filling of the BSD socket layer will be damaged. POSIX started with size_t, Linus Torvalds (he wanted more people, but apparently not a lot) and tried to explain to them that using size_t is totally wrong, because in the 64-bit structure, the length of size_t and int is different, and the length of this parameter (that is, the third parameter of the accept function) must be the same as that of int, this is the BSD socket interface standard. in the end, the POSIX guys found a solution, which is to create a new type "socklen_t ". linux Torvalds says this is because they have found their own errors but are embarrassed to admit it to the big guys, so they have created a new data type.


To enhance program portability, We have size_t, which is defined to facilitate migration between systems. size_t may be different in different systems.

It is defined as unsigned int on a 32-bit system.
That is to say, on a 32-bit system, it is a 32-bit unsigned integer.

Defined as unsigned long on a 64-bit System
That is to say, in a 64-bit system, it is a 64-bit unsigned integer.

Size_t is generally used to indicate a type of counting, such as how many items are copied. For example, the result type of the sizeof operator is size_t,
This type ensures that it can accommodate the maximum object size.
It is generally an unsigned integer type suitable for measuring the number of data items that can be accommodated in the memory ".
Therefore, it is widely used in array subscript and memory management functions.

Ssize_t: indicates the size of data blocks that can be read/written. it is similar to size_t, but must be signed. meaning: it indicates the sign size_t type.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.