uint32_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的工程中必须做这样的工作。 由于涉及跨平台,而且每个平台的字长都不一样,因此预编译和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 createdbymarekmichalkiewiczmarekm @ Linux.org.pl
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