• size_t

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;

  • ptrdiff_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

time_t 在32和64位相同,都是用long来定义的:
/usr/include/linux/types.h:54:typedef __kernel_time_t              time_t;
/usr/include/asm/posix_types.h:21:typedef long             __kernel_time_t;

  • size_type

the Standard really defines it as,

template <class T>
class allocator
{
public:
typedef size_t size_type;
//.......
};

简单总结下:

long和指针char*在32位及64位下占用字节数一致,均是4和8.

在32位下要注意,long(time_t\size_t\size_type)、char*、这一阵营占用都是4,表面上与int、uint32_t、unsigned一样

uint64_t始终是8个字节的(即使在32bit下,会定义为long long来保证的,long long在64bit下同long一样8字节)如下:

#if __WORDSIZE == 64
typedef unsigned long int uint64_t;
#else
__extension__
typedef unsigned long long int uint64_t;
#endif

所以,在64bit下,long(time_t\size_t\size_type\uint64_t)、char*这一阵营占用都是8,与int、uint32_t、unsigned真不一样了。

一些基本的C/C++数据类型的更多相关文章

  1. JavaScript 中的数据类型

    Javascript中的数据类型有以下几种情况: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Function,Date,Ar ...

  2. JS 判断数据类型的三种方法

    说到数据类型,我们先理一下JavaScript中常见的几种数据类型: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Functi ...

  3. Python高手之路【二】python基本数据类型

    一:数字 int int(整型): 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统上,整数的位数为64位,取值 ...

  4. UniqueIdentifier 数据类型 和 GUID 生成函数

    UniqueIdentifier 数据类型用于存储GUID的值,占用16Byte. SQL Server将UniqueIdentifier存储为16字节的二进制数值,Binary(16),按照特定的格 ...

  5. SQL Server常见数据类型介绍

    数据表是由多个列组成,创建表时必须明确每个列的数据类型,以下列举SQL Server常见数据类型的使用规则,方便查阅. 1.整数类型 int 存储范围是-2,147,483,648到2,147,483 ...

  6. 由js apply与call方法想到的js数据类型(原始类型和引用类型)

    原文地址:由js apply与call方法想到的js数据类型(原始类型和引用类型) js的call方法与apply方法的区别在于第二个参数的不同,他们都有2个参数,第一个为对象(即需要用对象a继承b, ...

  7. python 数据类型 ----字典

    字典由一对key:value 组成的 python中常用且重量级的数据类型 1. key , keys, values 字典由一对key:value 组成的 python中常用且重量级的数据类型 1. ...

  8. SQL数据类型

    1.Character 字符串: 数据类型 描述 存储 char(n) 固定长度的字符串.最多8,000个字符. n varchar(n) 可变长度的字符串.最多8,000个字符.   varchar ...

  9. 跟着老男孩教育学Python开发【第二篇】:Python基本数据类型

    运算符 设定:a=10,b=20 . 算数运算 2.比较运算 3.赋值运算 4.逻辑运算 5.成员运算 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**3 ...

  10. 我的MYSQL学习心得(二) 数据类型宽度

    我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...

随机推荐

  1. Linux下screen命令

    //1.列出当前的screenscreen -ls //2.新建一个screen,直接在命令行键入screen命令 screen -S [会话名称][root@www.lnuxidc.com ~]# ...

  2. EF学习笔记(二)

    DbContext 1.指定连接字符串(上一章提到) public string ConnectionStringName { get; private set; } /// <summary& ...

  3. 关于resolve非泛型方法不能与类型实参一起使用

    今天mvc新建三层时,写到bll层中一直报下面的错误,检查了几遍赶脚并没有什么错.最后发现缺少一些引用. 如下面的图,少添加了下面的两个引用.Unity是微软模式与实践团队开发的一个轻量级.可扩展的依 ...

  4. PAT 10-0 说反话

    我写了两种实现方法,其中第二种是参考Yomman园友的(http://www.cnblogs.com/yomman/p/4271949.html).我的方法(方法一)是用一个数组存放输入的字符串,另一 ...

  5. STM32下载显示target dll has been cancelled

    使用MDK 4.74向STM32下载时出现各种错误,而且时隐时现, Internal command error.Error:Flash download failed. Target DLL has ...

  6. 2016 - 1 - 22 HTTP(二)

    一: 发送HTTP请求的方法 1.在HTTP/1.1中规定了8种发送请求的方法: 2.发送请求时需要参数,比如POST中的账号密码 二:POST与GET的对比 1.GET与POST的主要区别表现在数据 ...

  7. javascript正则表达式替换字符串

    var reg = /^per_list(.*)[\d]{1,}(.*)/;var str = "per_listAmtApril1.value";var replaceStr = ...

  8. 使用isEqual来比较对象

    比较对象 您可以使用 isEqual: 方法比较两个对象.让接收消息的对象与传入的对象进行比较:如果相同,该方法返回 YES.例如: BOOL objectsAreEqual = [obj1 isEq ...

  9. BZOJ3028 食物 (生成函数)

    首先 1+x+x^2+x^3+...+x^∞=1/(1-x) 对于题目中的几种食物写出生成函数 (对于a*x^b , a表示方案数 x表示食物,b表示该种食物的个数) f(1)=1+x^2+x^4+. ...

  10. Magento中,调用静态块的几种方法

    在后台创建一个order_form静态块Block Title :Order FormIdentifier :order_formStatus :EnabledContent :自定义内容 1.如果要 ...