uint8_t/uint16_t/uint32_t/uint64_t 等是什么数据类型

时间:2022-09-06 11:56:32

我想,uint8、uint16、uint32、uint64 这大家可能比较理解unit,unsigned int 嘛

uint8,我想很多人也能够理解,其实是unsigned char

那么 _t 呢?其实就是 typedef 的意思

我们在学习标准的C语言时,常见的有 bit、char、short、int、long、float、double等

却几乎不曾见到uint8、uint16 等

所以,人家在这些自定义数据类型后面加 _t 来表示这些数据类型是 typedef 的

以上数据类型在C99中定义如下,其他地方的引用也大同小异了。


这些数据类型是 C99 中定义的,具体定义在:/usr/include/stdint.h    ISO C99: 7.18 Integer types


  1.   
  2. #ifndef __int8_t_defined  
  3. # define __int8_t_defined  
  4. typedef signed char             int8_t;   
  5. typedef short int               int16_t;  
  6. typedef int                     int32_t;  
  7. # if __WORDSIZE == 64  
  8. typedef long int                int64_t;  
  9. # else  
  10. __extension__  
  11. typedef long long int           int64_t;  
  12. # endif  
  13. #endif  
  14.   
  15.   
  16. typedef unsigned char           uint8_t;  
  17. typedef unsigned short int      uint16_t;  
  18. #ifndef __uint32_t_defined  
  19. typedef unsigned int            uint32_t;  
  20. # define __uint32_t_defined  
  21. #endif  
  22. #if __WORDSIZE == 64  
  23. typedef unsigned long int       uint64_t;  
  24. #else  
  25. __extension__  
  26. typedef unsigned long long int  uint64_t;  
  27. #endif