Why are function parameters of type size_t?

The prototype of memset is void *memset(void *s, int c, size_t n);. So why is the third parameter of type size_t? memset- just an example, I want more general reasons. Thanks in advance.

+5
source share
4 answers

size_tis a return type of operator sizeofand is used to describe memory sizes. In the case, memsetit indicates the number of bytes (n) in the memory block, which should be set to the set value (c).

The size in bits size_tdepends on the address space of the target platform. It does not always correlate with register size. For example, in a segmented memory architecture, there sizeof (size_t)may be less than sizeof (void *). As a rule, there size_twill be 4 bytes on a 32-bit machine, 8 bytes on a 64-bit machine, etc.

+5
source

size_tis the type used to indicate the size of objects. In C, the sizes of integer types ( int, longetc.) depend on the implementation, and you need to use the correct type for each implementation of the compiler p so that the size is large enough to store all possible values.

, SDK , typedef, size_t . memset() , .

+2

size_t is a type suitable for representing the amount of memory required by object data. This is an unsigned integer type (usually typedef unsigned int size_t;).

Read this link for more details .

+1
source

size_t guaranteed to be large enough to hold the pointer on all platforms.

-2
source

All Articles