views:

521

answers:

5

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?

A: 

That's a type that's used throughout C and C++ to simply represent an integer. I believe it's just a typedef of int.

Marc W
The Single Unix Specification defines it as an "unsigned integral type" but you shouldn't assume anything about actual width. size_t is almost always unsigned, however, while ssize_t is typically signed to allow it to indicate error conditions with a -1.
Jason Coco
+11  A: 

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.

Otávio Décio
+1  A: 

size_t is an alias (typedef) for an unsigned integer.

Jekke
So there I could also write NSUInteger w = CGImageGetWidth(inImage); ?
Thanks
I don't recognize that one off-hand, but you should be able to write uint w = CGImageGetWidth(inImage);. Typedefs like size_t are usually for clarity of purpose, not definition of structure.
Jekke
+2  A: 

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.

Remus Rusanu
A: 

Terminology. size_t.

Andrey Karpov