原文鏈接:https://blog.csdn.net/whstudio123/article/details/104144306
在 KELI MDK 數據類型中進了如下定義
char 占用 1 個字節
short int 占用 2 字節//注意這里!
int 占用 4 字節
long 占用 4 字節 //注意這里!
long int 占用 4 字節 //注意這里!
float 占用 4 字節
double 占用 8 字節即有如下宏定義
typedef unsigned char uint8; // 無符號 8 位字符型變量
typedef signed char int8; // 有符號 8 位字符型變量
typedef unsigned short uint16; // 無符號 16 位短整型變量
typedef signed short int16; // 有符號 16 位短整型變量
typedef unsigned int uint32; // 無符號 32 位整型變量
typedef signed int int32; // 有符號 32 位整型變量
typedef float fp32; // 單精度浮點數(32 位長度)
typedef double fp64; // 雙精度浮點數(64 位長度)
注:C 語言中的種類數據:整型:int short long 實型:float, double 。其中,Unsigned 為無符號, signed 有符號。
STM32 采用了大量的固件庫,其中在 2.0 庫中有 24 個數據類型如下
typedef unsigned char u8;/*無符號 8 位變量**/0~255 一字節
typedef signed char s8;/**有符號 8 位變量*/-128~127
typedef volatile unsigned char vu8;/* 易變的 8 位無符號變量**/
typedef volatile signed char vs8;/* 易變的 8 位有符號變量*/
typedef unsigned char const uc8; /* 只讀的 8 位無符號變量 */
typedef signed char const sc8; /* 只讀的 8 位有符號變量 */
typedef volatile unsigned char const vuc8; /* 易變只讀的 8 位無符變量*/
typedef volatile signed char const vsc8; /* 易變只讀 8 位有符號變量 */
typedef unsigned short u16; /*16 位短整型無符號變量**/0~65535 兩字節
typedef signed short s16; /*16 位短整型有符號變量**/-32768~32767 兩字節
typedef volatile unsigned short vu16;
typedef volatile signed short vs16;
typedef unsigned short const uc16; /* Read Only */
typedef signed short const sc16; /* Read Only */
typedef signed short const sc16; /* Read Only */
typedef volatile unsigned short const vuc16; /* Read Only */
typedef volatile signed short const vsc16; /* Read Only */
typedef unsigned long u32; /*32 位長整型無符號變量**/0~(2^32-1)四字節
typedef signed long s32; //*[(-2^32)/2]~ [(-2^32)/2-1]四字節
typedef volatile unsigned long vu32;
typedef volatile signed long vs32;
typedef unsigned long const uc32; /* Read Only */
typedef signed long const sc32; /* Read Only */
typedef volatile unsigned long const vuc32; /* Read Only */
typedef volatile signed long const vsc32; /* Read Only */
對部分數據類型后面作了注釋,其它類型類推。對於float int 編譯器中不能看到其定義(估計已編譯了)。
不同類型數據的混合運算在C 語言中,不同類型的數據間是可以混合運算的。在進行運算時,不同類型的數據要先轉換成同一類型,然后進行運算。轉換的規則如下: