Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of data is size_t holding?

In a code-snippet I have seen this:

size_t w = CGImageGetWidth(inImage);

The docs don't give me any useful info about "size_t". Does anyone know what this is?

like image 527
Thanks Avatar asked May 14 '09 19:05

Thanks


People also ask

What is the data type of Size_t?

The datatype size_t is unsigned integral type. It represents the size of any object in bytes and returned by sizeof operator. It is used for array indexing and counting. It can never be negative.

Is Size_t an int?

In C++, size_t is an unsigned integer type that is the result of the “sizeof” operator.

Why do people use Size_t?

size_t is used to store sizes of data objects, and is guaranteed to be able to hold the size of any data object that the particular C implementation can create. This data type may be smaller (in number of bits), bigger or exactly the same as unsigned int.


2 Answers

size_t is a platform dependent means to represent size of objects. It is always unsigned, but the it can be an unsigned 32 bit value on 32bit platforms or 64 bit value for 64bit platforms. On iPhone SDK is an unsigned long.

like image 178
Remus Rusanu Avatar answered Nov 08 '22 20:11

Remus Rusanu


From here:

Unsigned integral type

size_t corresponds to the integral data type returned by the language operator sizeof and is defined in the header file (among others) as an unsigned integral type.

In <cstring>, it is used as the type of the parameter num in the functions memchr, memcmp, memcpy, memmove, memset, strncat, strncmp, strncpy and strxfrm, which in all cases it is used to specify the maximum number of bytes or characters the function has to affect.

It is also used as the return type for strcspn, strlen, strspn and strxfrm to return sizes and lengths.

like image 45
Otávio Décio Avatar answered Nov 08 '22 20:11

Otávio Décio