不同平台的size_t会用不同的类型实现,使用size_t而非int或unsigned可以写出扩展行更好的代
C:
size_t一般用来表示一种计数,比如有多少东西被拷贝等。sizeof操作符的结果类型是size_t,数组大小也是size_t类型。
它在头文件中typedef为unsigned int类型,即typedef unsigned int size_t
该类型保证能容纳实现所建立的最大对象的字节大小。strncat,strncmp,strncpy等都用到了它。
size_t 是为了方便系统之间的移植而定义的,在32位系统上定义为 unsigned int,在64位系统上定义为 unsigned long。
C++:
vector的大小和下标是size_type类型,也是无符号型。
// Definitions of common types
#ifdef _WIN64
typedef unsigned __int64 size_t;
typedef __int64 ptrdiff_t;
typedef __int64 intptr_t;
#else
typedef unsigned int size_t;
typedef int ptrdiff_t;
typedef int intptr_t;
#endif