一些基本的C/C++数据类型
- 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++数据类型的更多相关文章
- JavaScript 中的数据类型
Javascript中的数据类型有以下几种情况: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Function,Date,Ar ...
- JS 判断数据类型的三种方法
说到数据类型,我们先理一下JavaScript中常见的几种数据类型: 基本类型:string,number,boolean 特殊类型:undefined,null 引用类型:Object,Functi ...
- Python高手之路【二】python基本数据类型
一:数字 int int(整型): 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位系统上,整数的位数为64位,取值 ...
- UniqueIdentifier 数据类型 和 GUID 生成函数
UniqueIdentifier 数据类型用于存储GUID的值,占用16Byte. SQL Server将UniqueIdentifier存储为16字节的二进制数值,Binary(16),按照特定的格 ...
- SQL Server常见数据类型介绍
数据表是由多个列组成,创建表时必须明确每个列的数据类型,以下列举SQL Server常见数据类型的使用规则,方便查阅. 1.整数类型 int 存储范围是-2,147,483,648到2,147,483 ...
- 由js apply与call方法想到的js数据类型(原始类型和引用类型)
原文地址:由js apply与call方法想到的js数据类型(原始类型和引用类型) js的call方法与apply方法的区别在于第二个参数的不同,他们都有2个参数,第一个为对象(即需要用对象a继承b, ...
- python 数据类型 ----字典
字典由一对key:value 组成的 python中常用且重量级的数据类型 1. key , keys, values 字典由一对key:value 组成的 python中常用且重量级的数据类型 1. ...
- SQL数据类型
1.Character 字符串: 数据类型 描述 存储 char(n) 固定长度的字符串.最多8,000个字符. n varchar(n) 可变长度的字符串.最多8,000个字符. varchar ...
- 跟着老男孩教育学Python开发【第二篇】:Python基本数据类型
运算符 设定:a=10,b=20 . 算数运算 2.比较运算 3.赋值运算 4.逻辑运算 5.成员运算 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**3 ...
- 我的MYSQL学习心得(二) 数据类型宽度
我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
随机推荐
- Cisco IOS basic system management command reference
absolute : to specify an absolute time for a time-range (in time-range configuration mode) no absolu ...
- 支撑向量机(SVM)
转载自http://blog.csdn.net/passball/article/details/7661887,写的很好,虽然那人也是转了别人的做了整理(最原始文章来自http://www.blog ...
- java多线程的协作
java多线程之间相互协作,主要有join, yield, interupt(), sleep, wait, notify, notifyAll; join: 在一个线程A的代码里面调用另 ...
- Get start with Android development
Firstly we should install the right version of JDK and JRE, there are two version of ADK for differe ...
- Linux----七个有效的文本编辑习惯
如果你要花大量的时间键入文本, 写程序或编写HTML脚本, 你可以通过有效地使用一个好的编辑器来替你节省时间. 本文将引导你如果快速地完成你的编辑工作, 并且减少你的错误. 本文将以开放源码软件Vim ...
- 头文件定义和ARM指令
2015.2.2星期一,阴天 内存管理:内存的分配和释放等静态和动态内存:主要是在释放方式上的区别 静态变量:编译时就已经确定,定义在函数外面自动变量:在程序运行时才能在栈中确定只读数据节:存放常量的 ...
- 当前页面js代码
<script type="text/javascript"> var url = location.href; $(function(){ var url = loc ...
- Linux基础入门(新版)(实验九-实验十二)
实验九 简单文本入门 一.常用的文本处理命令 二.文本处理命令 1.tr 命令 tr 命令可以用来删除一段文本信息中的某些文字.或者将其进行转换. 使用方式: tr [option]...SET1 [ ...
- WP8.1 双击两次返回键退出程序
在实现Windows Phone上实现点按两次返回键退出程序, 一种方法是使用Coding4Fun提供的ToastPrompt, 使用方法如下: 1. 安装引用, 打开Package Manager ...
- 第二个Sprint冲刺第四天
讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 今天的发展,探讨了统计功能的问题: 一.统计数据针对的是什么功能? 1.初衷是针对计时的填空题,至于其它功能统不统计,那要看开发的进度. 二.对 ...