Size_t and ssize_t

Source: Internet
Author: User

Ssize_t and size_t

Track the Linux source code to get the following macros:

 

# Ifndef _ size_t

# DEFINE _ size_t

Typedef _ kernel_size_t size_t;

# Endif

 

# Ifndef _ ssize_t

# DEFINE _ ssize_t

Typedef _ kernel_ssize_t ssize_t;

# Endif

 

Different platforms have different definitions:

/* 64-bit */

Typedef unsigned long _ kernel_size_t;

Typedef long _ kernel_ssize_t;

 

/* Linux 32 bit */

Typedef unsigned int _ kernel_size_t;

Typedef int _ kernel_ssize_t;

This is the actual definition of two types, literally:

Ssize_t = signed size_t

 

Usage location:

Size_t is generally used for the length of non-negative values such as the buffer size;

For Image

Ssize_t (* read) (struct file *, char _ User *, size_t, loff_t *);

Ssize_t (* write) (struct file *, const char _ User *, size_t, loff_t *);

Ssize_t (* aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t );

Ssize_t (* aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t );

If the <0 function is returned for failure, ssize_t is used;

 

Ssize_t (* read) (struct file *, char _ User *, size_t, loff_t *);

Another similar type: loff_t

Definition:

# If defined (_ gnuc __)

Typedef _ kernel_loff_t loff_t;

# Endif

Is a long type.

# Ifdef _ gnuc __

Typedef long _ kernel_loff_t;

# Endif

More: http://blog.csdn.net/lalor/article/details/7426184

Size_t and ssize_t

Related Article

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.