C语言中int 类型的字节长度
来源:互联网 发布:wind数据库怎么用 编辑:程序博客网 时间:2024/06/07 00:44
int 这个数据类型比较特殊,具体分配的字节数与机器字长和编译器有关。如果要保证移植性,尽量用__int16 __int32 __int64 ,__int16、__int32,_int64 这些数据类型在所有平台下都分配相同的字节。所以在移植上不存在问题。
所谓的不可移植是指:在一个平台上编写的代码无法拿到另一个平台上运行时,不能达到期望的运行结果 。
例如:在32为平台上(所谓32位平台是指通用寄存器的 数据宽度是32)编写代码,int 类型分配4个字节,而在16位平台是则分配2个字节,那么在16位上编译出来的exe,其中是为int分配2字节,而在32位平台上运行时,会按照4个字 节来解析,显然会出错误的!!
而对于非int类型,目前为止,所有的类型分配的字节数都是兼容的,即不同平台对于同一个类型分配相同的字节数!!
建议:在代码中尽量避免使用int类型,根据不同的需要可以用short,long等代替。
下表是关于常见数据类型字节长度的总结
数据类型名称字节数别名取值范围 int*signed,signed int由 操作系统 决定,即与操作系统的"字长"有关 unsigned int*unsigned由操作系统决定,即与操作系统的"字长"有关__int81char,signed char–128 ~ 127__int162short,short int,signed short int–32,768 ~ 32,767__int324signed,signed int–2,147,483,648 ~ 2,147,483,647__int648无–9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807bool1无false 或 truechar1signed char–128 到 127unsigned char1无0 到 255short2short int,signed short int–32,768 到 32,767unsigned short2unsigned short int0 到 65,535
- C语言中int 类型的字节长度
- 不同语言的变量类型及字节长度 (C & Java)
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 在C语言中,double long unsigned int char 类型数据所占字节数
- 在C语言中,double、long、unsigned、int、char类型数据所占字节数
- 线程同步之事件对象
- 自定义标签viewIP的步骤
- PhotoShop中与我有关的连接
- 术语Misc设备类型
- android无用之“迷思”
- C语言中int 类型的字节长度
- 超级强大的下载工具wget
- 常用ARM汇编指令及ATPCS规则
- 关于 typedef 关键字的用法讲解:
- 使用python和redis实现实时聊天室
- 验证码
- 支付宝接口
- [arm]GNU ARM 汇编指令
- 列举某个表作为主键被别人引用的外键