关于基本数据类型的定义

写这篇博文的目的就是为了清晰的缕一下自己的思路,把用到的记录下来以便将来方便使用。

基础类型

char:1个字节
short:2个字节
int:在51等8位单片机下为2字节,32位RAM单片机下为4字节​(在考虑不同平台移植时最好用short和long
long:4个字节​
float:4个字节
double:8个字节

下面是stm32中常用到的类型:​

u8 是 unsigned char
u16 是 unsigned short
u32 是 unsigned int(32位下,下面省略)

关于uint8_t/uint16_t/uint32_t/uint64_t 等数据类型​

在inttypes.h下可以看到



#ifndef __INTTYPES_H_

#define __INTTYPES_H_



typedef signed char int8_t;

typedef unsigned char uint8_t;



typedef int int16_t;

typedef unsigned int uint16_t;



typedef long int32_t;

typedef unsigned long uint32_t;



typedef long long int64_t;

typedef unsigned long long uint64_t;



typedef int16_t intptr_t;

typedef uint16_t uintptr_t;



#endif

使用uint_t定义更加方便,由于使用了typedef(为C语言的关键字,作用是为一种数据类型定义一个新名字。)使得在不同的平台下更好的移植。

还有三种遇到的类型​

typedef __IO int32_t  vs32;

typedef __IO int16_t  vs16;

typedef __IO int8_t   vs8;

这里有__IO的定义#define __IO volatile

volatile 影响编译器编译的结果,指出,volatile 变量是随时可能发生变化的,与volatile变量有关的运算,不要进行编译优化,以免出错。

它的作用使得编译器​每次都会调用它本身,不会因为变量因为寄存器等变化出现错误,volatile可以保证对特殊地址的稳定访问,不会出错。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值