标签:
size_t. A basic unsigned integer C/C++ type. It is the type of the result returned by sizeof operator. The type‘s size is chosen so that it could store the maximum size of a theoretically possible array of any type. On a 32-bit system size_t will take 32 bits and on a 64-bit one - 64 bits. In other words, a pointer can be safely put inside size_t type (an exception is class-function-pointers but this is a special case). size_t type is usually used for loop, array indexing, size storage and address arithmetic. Although size_t can store a pointer, it is better to use another unsinged integer type uintptr_t for that purpose (its name reflects its capability). In some cases using size_t type is more effective and safe than using a more habitual for the programmer unsigned type.
size_t is a base unsigned integer memsize-type defined in the standard library of C/C++ languages. This type is described in the header file stddef.h for C and in the file cstddef for C++. Types defined by the header file stddef.h are located in the global namespace while cstddef places the size_t type in the namespace std. Since the standard header file stddef.h of the C language is included into C++ programs for the purpose of compatibility, in these programs you may address the type both in the global namespace (::size_t, size_t) and namespace std (std::size_t).
32:
/usr/include/asm/posix_types.h:18:typedef unsigned int __kernel_size_t;
/usr/include/linux/types.h:39:typedef __kernel_size_t size_t;
64:
/usr/include/asm-i386/posix_types.h:18:typedef unsigned int __kernel_size_t;
/usr/include/asm-x86_64/posix_types.h:18:typedef unsigned long __kernel_size_t;
/usr/include/linux/types.h:39:typedef __kernel_size_t size_t;
A basic signed integer C/C++ type. The type‘s size is chosen so that it could store the maximum size of a theoretically possible array of any type. On a 32-bit system ptrdiff_t will take 32 bits and on a 64-bit one - 64 bits. In other words, a pointer can be safely put inside ptrdiff_t type (an exception is class-function-pointers but this is a special case). By the way the result of the expression where one pointer is subtracted from another (ptr1-ptr2) will have ptrdiff_t type. ptrdiff_t type is usually used for loop, array indexing, size storage and address arithmetic. ptrdiff_t type has its synonym intptr_t whose name indicates more clearly that it can store a pointer. In some cases using ptrdiff_t type is more effective and safe than using a more habitual for the programmer int type.
time_t 在32和64位相同:
/usr/include/linux/types.h:54:typedef __kernel_time_t time_t;
/usr/include/asm/posix_types.h:21:typedef long __kernel_time_t;
在32bit下,time_t的存储要注意,不等同于size_t\unsigned等。
size_t\prtdiff_t\time_t都是基于long的,所以与服务器相关!
the Standard really defines it as,
template <class T>
class allocator
{
public:
typedef size_t size_type;
//.......
};
标签:
原文地址:http://www.cnblogs.com/leby/p/4469358.html