uint16_t范围,uint16_t是什么类型
uint8_ t/uint 16 _ t/uint 32 _ t/uint 64 _ t是什么数据类型
在nesc的代码中,未知的数据类型非常常见,例如uint8_t。 乍一看。 好像是新的数据类型。 但是,c语言(nesc是c的扩展功能)中好像没有这样的数据类型。 为什么又是u又是_t的呢? 很多人都有这样的疑问。 在论坛上,以*_t结尾的类型都是long型吗? 在百度上查了一下,终于找到了答案。 那时,我发现自己对c掌握得不多。
那么_t的意思到底表示什么呢? 没有找到的公式的答案。 只是,我想有接近的答案。 那是结构的加价。 可以理解为type/typedef的缩写表示它是在typedef中定义的,而不是在其他数据类型中定义的。
uint8_t,uint16_t。 uint32_t等不是新的数据类型。 这些只是使用typedef为类型分配的别名。 用新瓶子装旧酒的把戏。
只是,请不要轻视typedef。 它对你的代码维护有非常好的作用。
例如c没有bool,所以在软件里。 有些程序猴子用int,有些程序猴子用short的话会混乱。 最好用typedef定义。 例如,以下内容:
typedef char bool;
一般来说,在C的project中,由于涉及到跨平台,所以必须进行这样的工作。 字的长度因平台而异。 因此,利用预编译和typedef可以最有效地维护代码。 为了用户的方便。 C99标准的c语言硬件为我们定义了这些类型,所以可以放心使用。
根据posix标准,支持一般整形的*_t类型如下。
1字节uint8_t
2字节uint16_t
4字节uint32_t
8字节uint64_t
附: C99标准中inttypes.h的内容
00001 /*
00002inttypes.h
00003
00004连接器:
00005 createdbymarekmichalkiewicz
00006
00007 thissoftwareisnotcopyrighted
00008
00009 thissourcecodeisofferedforuseinthepublicdomain.you may
00010use,modify or distribute it freely。
00011
0012 thiscodeisdistributedinthehopethatitwillbeuseful,but
0013 withoutanywarranty.all warranties,EXPRESS OR IMPLIED ARE HEREBY
0014 disclaimed.thisincludesbutisnotlimitedtowarrantiesof
0015 merchantabilityorfitnessforaparticularpurpose。
00016*/
00017
00018 #ifndef __INTTYPES_H_
00019 #define __INTTYPES_H_
00020
0021/* use [ u ] intn _ tifyouneedexactlynbits。
0022 XXX-doesn ' thandle the-mint8option.* /
00023
00024typedefsigned char int8_t;
00025 typedef unsigned char uint8_ t;
00026
00027typedefint int16_t;
00028 typedef unsigned int uint 16 _ t;
00029
00030类型长整型32 _ t;
0031 typedefunsignedlonguint 32 _ t;
00032
00033类型龙龙int 64 _ t;
0034 typedefunsignedlonglonguint 64 _ t;
00035
00036typedefint16_t intptr_t;
00037typedefuint16_t uintptr_t;
00038
00039 #endif