求typedefsize_tsize_type;intup[16][16],down[16][16],onmousedown_dra

1498人阅读
学习(38)
uint8_t,uint16_t,uint32_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来定义,如:
一般来说,一个C的工程中一定要做一些这方面的工作,因为你会涉及到跨平台,不同的平台会有不同的字长,所以利用预编译和typedef可以让你最有效的维护你的代码。为了用户的方便,C99标准的C语言硬件为我们定义了这些类型,我们放心使用就可以了。
&按照posix标准,一般整形对应的*_t类型为:
1字节 & & uint8_t
2字节 & & uint16_t
4字节 & & uint32_t
8字节 & & uint64_t
STM32里的类型定义,见如下说明:
/* Exported types ------------------------------------------------------------*/
typedef signed long &s32;
typedef signed short s16;
typedef signed char &s8;
typedef signed long &const sc32; &/* Read Only */
typedef signed short const sc16; &/* Read Only */
typedef signed char &const sc8; & /* Read Only */
typedef volatile signed long &vs32;
typedef volatile signed short vs16;
typedef volatile signed char &vs8;
typedef volatile signed long &const vsc32; &/* Read Only */
typedef volatile signed short const vsc16; &/* Read Only */
typedef volatile signed char &const vsc8; & /* Read Only */
typedef unsigned long &u32;
typedef unsigned short u16;
typedef unsigned char &u8;
typedef unsigned long &const uc32; &/* Read Only */
typedef unsigned short const uc16; &/* Read Only */
typedef unsigned char &const uc8; & /* Read Only */
typedef volatile unsigned long &vu32;
typedef volatile unsigned short vu16;
typedef volatile unsigned char &vu8;
typedef volatile unsigned long &const vuc32; &/* Read Only */
typedef volatile unsigned short const vuc16; &/* Read Only */
typedef volatile unsigned char &const vuc8; & /* Read Only */
Exported_types
&Stm32f10x&
typedef int32_t &s32&
typedef int16_t &s16&
typedef int8_t &s8&
typedef const int32_t &sc32&
typedef const int16_t &sc16&
typedef const int8_t &sc8&
typedef __IO int32_t &vs32&
typedef __IO int16_t &vs16&
typedef __IO int8_t &vs8&
typedef __I int32_t &vsc32&
typedef __I int16_t &vsc16&
typedef __I int8_t &vsc8&
typedef uint32_t &u32&
typedef uint16_t &u16&
typedef uint8_t &u8&
typedef const uint32_t &uc32&
typedef const uint16_t &uc16&
typedef const uint8_t &uc8&
typedef __IO uint32_t &vu32&
typedef __IO uint16_t &vu16&
typedef __IO uint8_t &vu8&
typedef __I uint32_t &vuc32&
typedef __I uint16_t &vuc16&
typedef __I uint8_t &vuc8
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:6451次
排名:千里之外
原创:38篇
(8)(21)(2)(3)(4)(3)(1)(1)

我要回帖

更多关于 lather over body 的文章

 

随机推荐