uint8_t / uint16_t / uint32_t /uint64_t
来源:互联网 发布:linux 删除组成员 编辑:程序博客网 时间:2024/05/01 23:24
uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
在nesc的代码中,你会看到很多你不认识的数据类型,比如uint8_t等。咋一看,好像是个新的数据类型,不过C语言(nesc是C的扩展)里面好像没有这种数据类型啊!怎么又是u又是_t的?很多人有这样的疑问。论坛上就有人问:以*_t结尾的类型是不是都是long型的?在baidu上查一下,才找到答案,这时才发觉原来自己对C掌握的太少。
那么_t的意思到底表示什么?具体的官方答案没有找到,不过我觉得有个答案比较接近。它就是一个结构的标注,可以理解为type/typedef的缩写,表示它是通过typedef定义的,而不是其它数据类型。
uint8_t,uint16_t,uint32_t等都不是什么新的数据类型,它们只是使用typedef给类型起的别名,新瓶装老酒的把戏。不过,不要小看了typedef,它对于你代码的维护会有很好的作用。比如C中没有bool,于是在一个软件中,一些程序员使用int,一些程序员使用short,会比较混乱,最好就是用一个typedef来定义,如:
typedef char bool;
一般来说,一个C的工程中一定要做一些这方面的工作,因为你会涉及到跨平台,不同的平台会有不同的字长,所以利用预编译和typedef可以让你最有效的维护你的代码。为了用户的方便,C99标准的C语言硬件为我们定义了这些类型,我们放心使用就可以了。
按照posix标准,一般整形对应的*_t类型为:
1字节 uint8_t
2字节 uint16_t
4字节 uint32_t
8字节 uint64_t
附:C99标准中inttypes.h的内容
00001 /*
00002 inttypes.h
00003
00004 Contributors:
00005 Createdby Marek Michalkiewicz <marekm@linux.org.pl>
00006
00007 THISSOFTWARE IS NOT COPYRIGHTED
00008
00009 Thissource code is offered for use in the public domain. You may
00010 use,modify or distribute it freely.
00011
00012 Thiscode is distributed in the hope that it will be useful, but
00013 WITHOUTANY WARRANTY. ALLWARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
00014 DISCLAIMED. This includes but is not limited towarranties of
00015 MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.
00016 */
00017
00018 #ifndef __INTTYPES_H_
00019 #define __INTTYPES_H_
00020
00021 /* Use [u]intN_t if you need exactly N bits.
00022 XXX- doesn't handle the -mint8 option. */
00023
00024 typedefsigned char int8_t;
00025 typedefunsigned char uint8_t;
00026
00027 typedefint int16_t;
00028 typedefunsigned int uint16_t;
00029
00030 typedeflong int32_t;
00031 typedefunsigned long uint32_t;
00032
00033 typedeflong long int64_t;
00034 typedefunsigned long long uint64_t;
00035
00036 typedefint16_t intptr_t;
00037 typedefuint16_t uintptr_t;
00038
00039 #endif
这些数据类型是 C99 中定义的,具体定义在:/usr/include/stdint.h ISO C99: 7.18 Integer types <stdint.h>
1 /* There is some amount of overlap with <sys/types.h> as known by inet code */ 2 #ifndef __int8_t_defined 3 # define __int8_t_defined 4 typedef signed char int8_t; 5 typedef short int int16_t; 6 typedef int int32_t; 7 # if __WORDSIZE == 64 8 typedef long int int64_t; 9 # else10 __extension__11 typedef long long int int64_t;12 # endif13 #endif14 15 /* Unsigned. */16 typedef unsigned char uint8_t;17 typedef unsigned short int uint16_t;18 #ifndef __uint32_t_defined19 typedef unsigned int uint32_t;20 # define __uint32_t_defined21 #endif22 #if __WORDSIZE == 6423 typedef unsigned long int uint64_t;24 #else25 __extension__26 typedef unsigned long long int uint64_t;27 #endif
- uint8_t / uint16_t / uint32_t /uint64_t
- uint8_t / uint16_t / uint32_t /uint64_t
- uint8_t , uint16_t,uint32_t,uint64_t
- uint8_t / uint16_t / uint32_t /uint64_t
- uint8_t / uint16_t / uint32_t /uint64_t
- uint8_t / uint16_t / uint32_t /uint64_t
- uint8_t / uint16_t / uint32_t /uint64_t 数据类型
- 数据类型 uint8_t uint16_t uint32_t uint64_t
- uint8_t / uint16_t / uint32_t /uint64_t 数据类型
- UINT8_T / UINT16_T / UINT32_T /UINT64_T讲解
- uint8_t / uint16_t / uint32_t /uint64_t数据类型
- uint8_t / uint16_t / uint32_t /uint64_t 相关内容
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
- uint8_t / uint16_t / uint32_t /uint64_t 的简单介绍
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
- uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型
- uint8_t / uint16_t / uint32_t /uint64_t 的简单介绍
- c语言基础概念(3)
- 归并排序
- swustOJ 1615寻宝
- spring-mvc.xml参考
- js定义对象的方法和继承的方法
- uint8_t / uint16_t / uint32_t /uint64_t
- Disunity_V0.5.0 提取Unity生成的Apk的资源
- 实战iOS7之NSURLSession
- [乱搞] BZOJ 2296 [POJ Challenge] 随机种子
- Java 浅谈集合框架
- Jquery开发插件
- C#语言中提供了枚举和整型之间的强制转换功能(SelectItem)
- js--引用类型单体内置对象--Math,随机数生成
- Android高级UI之ViewPager实现页卡的最新方法-简洁的TabLayout