size-t

size_t vs. uintptr_t

六月ゝ 毕业季﹏ 提交于 2019-11-26 01:41:35
问题 The C standard guarantees that size_t is a type that can hold any array index. This means that, logically, size_t should be able to hold any pointer type. I\'ve read on some sites that I found on the Googles that this is legal and/or should always work: void *v = malloc(10); size_t s = (size_t) v; So then in C99, the standard introduced the intptr_t and uintptr_t types, which are signed and unsigned types guaranteed to be able to hold pointers: uintptr_t p = (size_t) v; So what is the

unsigned int vs. size_t

青春壹個敷衍的年華 提交于 2019-11-26 01:24:47
问题 I notice that modern C and C++ code seems to use size_t instead of int / unsigned int pretty much everywhere - from parameters for C string functions to the STL. I am curious as to the reason for this and the benefits it brings. 回答1: The size_t type is the unsigned integer type that is the result of the sizeof operator (and the offsetof operator), so it is guaranteed to be big enough to contain the size of the biggest object your system can handle (e.g., a static array of 8Gb). The size_t

What is size_t in C?

半世苍凉 提交于 2019-11-26 01:21:25
问题 I am getting confused with size_t in C. I know that it is returned by the sizeof operator. But what exactly is it? Is it a data type? Let\'s say I have a for loop: for(i = 0; i < some_size; i++) Should I use int i; or size_t i; ? 回答1: From Wikipedia: According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bit (see sections 7.17 and 7.18.3). size_t is an unsigned data type defined by several C/C++ standards, e.g. the C99 ISO/IEC 9899 standard, that is