C++ 数据类型

C++ 的主要数据类型,主要分为三类:布尔型整型(char型从本质上说,也是种整型类型,它是长度为1的整数,通常用来存放字符的ASCII码),浮点型

而 *_t是typedef定义的表示标志,是结构的一种标注。即我们所看到的 uint8_t、uint16_t、uint32_t都不是新的数据类型,而是通过typedef给类型起得别名。

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

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

  1. /* There is some amount of overlap with <sys/types.h> as known by inet code */
  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. /* Unsigned. */
  15. typedef unsigned char uint8_t;
  16. typedef unsigned short int uint16_t;
  17. #ifndef __uint32_t_defined
  18. typedef unsigned int uint32_t;
  19. # define __uint32_t_defined
  20. #endif
  21. #if __WORDSIZE == 64
  22. typedef unsigned long int uint64_t;
  23. #else
  24. __extension__
  25. typedef unsigned long long int uint64_t;
  26. #endif