stdint.h 文件 int8_t uint8_t int16_t uint16_t (一)

按照posix标准,一般整型对应的*_t类型为:
1字节     uint8_t
2字节     uint16_t
4字节     uint32_t
8字节     uint64_t
[cpp]  view plain copy
  1. /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 
  2. This file is part of the GNU C Library. 
  3.  
  4. The GNU C Library is free software; you can redistribute it and/or 
  5. modify it under the terms of the GNU Lesser General Public 
  6. License as published by the Free Software Foundation; either 
  7. version 2.1 of the License, or (at your option) any later version. 
  8.  
  9. The GNU C Library is distributed in the hope that it will be useful, 
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
  12. Lesser General Public License for more details. 
  13.  
  14. You should have received a copy of the GNU Lesser General Public 
  15. License along with the GNU C Library; if not, write to the Free 
  16. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
  17. 02111-1307 USA. */  
  18.   
  19. /* 
  20. * ISO C99: 7.18 Integer types <stdint.h> 
  21. */  
  22.   
  23. #ifndef _STDINT_H  
  24. #define _STDINT_H   1  
  25.   
  26. #include <features.h>  
  27. #include <bits/wchar.h>  
  28. #include <bits/wordsize.h>  
  29.   
  30. /* Exact integral types. */  
  31.   
  32. /* Signed. */  
  33.   
  34. /* There is some amount of overlap with <sys/types.h> as known by inet code */  
  35. #ifndef __int8_t_defined  
  36. # define __int8_t_defined  
  37. typedef signed char     int8_t;  
  38. typedef short int       int16_t;  
  39. typedef int         int32_t;  
  40. # if __WORDSIZE == 64  
  41. typedef long int        int64_t;  
  42. # else  
  43. __extension__  
  44. typedef long long int       int64_t;  
  45. # endif  
  46. #endif  
  47.   
  48. /* Unsigned. */  
  49. typedef unsigned char       uint8_t;  
  50. typedef unsigned short int uint16_t;  
  51. #ifndef __uint32_t_defined  
  52. typedef unsigned int        uint32_t;  
  53. # define __uint32_t_defined  
  54. #endif  
  55. #if __WORDSIZE == 64  
  56. typedef unsigned long int   uint64_t;  
  57. #else  
  58. __extension__  
  59. typedef unsigned long long int uint64_t;  
  60. #endif  
  61.   
  62.   
  63. /* Small types. */  
  64.   
  65. /* Signed. */  
  66. typedef signed char     int_least8_t;  
  67. typedef short int       int_least16_t;  
  68. typedef int         int_least32_t;  
  69. #if __WORDSIZE == 64  
  70. typedef long int        int_least64_t;  
  71. #else  
  72. __extension__  
  73. typedef long long int       int_least64_t;  
  74. #endif  
  75.   
  76. /* Unsigned. */  
  77. typedef unsigned char       uint_least8_t;  
  78. typedef unsigned short int uint_least16_t;  
  79. typedef unsigned int        uint_least32_t;  
  80. #if __WORDSIZE == 64  
  81. typedef unsigned long int   uint_least64_t;  
  82. #else  
  83. __extension__  
  84. typedef unsigned long long int uint_least64_t;  
  85. #endif  
  86.   
  87.   
  88. /* Fast types. */  
  89.   
  90. /* Signed. */  
  91. typedef signed char     int_fast8_t;  
  92. #if __WORDSIZE == 64  
  93. typedef long int        int_fast16_t;  
  94. typedef long int        int_fast32_t;  
  95. typedef long int        int_fast64_t;  
  96. #else  
  97. typedef int         int_fast16_t;  
  98. typedef int         int_fast32_t;  
  99. __extension__  
  100. typedef long long int       int_fast64_t;  
  101. #endif  
  102.   
  103. /* Unsigned. */  
  104. typedef unsigned char       uint_fast8_t;  
  105. #if __WORDSIZE == 64  
  106. typedef unsigned long int   uint_fast16_t;  
  107. typedef unsigned long int   uint_fast32_t;  
  108. typedef unsigned long int   uint_fast64_t;  
  109. #else  
  110. typedef unsigned int        uint_fast16_t;  
  111. typedef unsigned int        uint_fast32_t;  
  112. __extension__  
  113. typedef unsigned long long int uint_fast64_t;  
  114. #endif  
  115.   
  116.   
  117. /* Types for `void *' pointers. */  
  118. #if __WORDSIZE == 64  
  119. # ifndef __intptr_t_defined  
  120. typedef long int        intptr_t;  
  121. # define __intptr_t_defined  
  122. # endif  
  123. typedef unsigned long int   uintptr_t;  
  124. #else  
  125. # ifndef __intptr_t_defined  
  126. typedef int         intptr_t;  
  127. # define __intptr_t_defined  
  128. # endif  
  129. typedef unsigned int        uintptr_t;  
  130. #endif  
  131.   
  132.   
  133. /* Largest integral types. */  
  134. #if __WORDSIZE == 64  
  135. typedef long int        intmax_t;  
  136. typedef unsigned long int   uintmax_t;  
  137. #else  
  138. __extension__  
  139. typedef long long int       intmax_t;  
  140. __extension__  
  141. typedef unsigned long long int uintmax_t;  
  142. #endif  


[cpp]  view plain copy
  1. /* The ISO C99 standard specifies that in C++ implementations these 
  2. macros should only be defined if explicitly requested. */  
  3. #if !defined __cplusplus || defined __STDC_LIMIT_MACROS  
  4.   
  5. # if __WORDSIZE == 64  
  6. # define __INT64_C(c) c ## L  
  7. # define __UINT64_C(c) c ## UL  
  8. # else  
  9. # define __INT64_C(c) c ## LL  
  10. # define __UINT64_C(c) c ## ULL  
  11. # endif  
  12.   
  13. /* Limits of integral types. */  
  14.   
  15. /* Minimum of signed integral types. */  
  16. # define INT8_MIN       (-128)  
  17. # define INT16_MIN      (-32767-1)  
  18. # define INT32_MIN      (-2147483647-1)  
  19. # define INT64_MIN      (-__INT64_C(9223372036854775807)-1)  
  20. /* Maximum of signed integral types. */  
  21. # define INT8_MAX       (127)  
  22. # define INT16_MAX      (32767)  
  23. # define INT32_MAX      (2147483647)  
  24. # define INT64_MAX      (__INT64_C(9223372036854775807))  
  25.   
  26. /* Maximum of unsigned integral types. */  
  27. # define UINT8_MAX      (255)  
  28. # define UINT16_MAX     (65535)  
  29. # define UINT32_MAX     (4294967295U)  
  30. # define UINT64_MAX     (__UINT64_C(18446744073709551615))  
  31.   
  32.   
  33. /* Minimum of signed integral types having a minimum size. */  
  34. # define INT_LEAST8_MIN     (-128)  
  35. # define INT_LEAST16_MIN    (-32767-1)  
  36. # define INT_LEAST32_MIN    (-2147483647-1)  
  37. # define INT_LEAST64_MIN    (-__INT64_C(9223372036854775807)-1)  
  38. /* Maximum of signed integral types having a minimum size. */  
  39. # define INT_LEAST8_MAX     (127)  
  40. # define INT_LEAST16_MAX    (32767)  
  41. # define INT_LEAST32_MAX    (2147483647)  
  42. # define INT_LEAST64_MAX    (__INT64_C(9223372036854775807))  
  43.   
  44. /* Maximum of unsigned integral types having a minimum size. */  
  45. # define UINT_LEAST8_MAX    (255)  
  46. # define UINT_LEAST16_MAX   (65535)  
  47. # define UINT_LEAST32_MAX   (4294967295U)  
  48. # define UINT_LEAST64_MAX   (__UINT64_C(18446744073709551615))  
  49.   
  50.   
  51. /* Minimum of fast signed integral types having a minimum size. */  
  52. # define INT_FAST8_MIN      (-128)  
  53. # if __WORDSIZE == 64  
  54. # define INT_FAST16_MIN    (-9223372036854775807L-1)  
  55. # define INT_FAST32_MIN    (-9223372036854775807L-1)  
  56. # else  
  57. # define INT_FAST16_MIN    (-2147483647-1)  
  58. # define INT_FAST32_MIN    (-2147483647-1)  
  59. # endif  
  60. # define INT_FAST64_MIN     (-__INT64_C(9223372036854775807)-1)  
  61. /* Maximum of fast signed integral types having a minimum size. */  
  62. # define INT_FAST8_MAX      (127)  
  63. # if __WORDSIZE == 64  
  64. # define INT_FAST16_MAX    (9223372036854775807L)  
  65. # define INT_FAST32_MAX    (9223372036854775807L)  
  66. # else  
  67. # define INT_FAST16_MAX    (2147483647)  
  68. # define INT_FAST32_MAX    (2147483647)  
  69. # endif  
  70. # define INT_FAST64_MAX     (__INT64_C(9223372036854775807))  
  71.   
  72. /* Maximum of fast unsigned integral types having a minimum size. */  
  73. # define UINT_FAST8_MAX     (255)  
  74. # if __WORDSIZE == 64  
  75. # define UINT_FAST16_MAX   (18446744073709551615UL)  
  76. # define UINT_FAST32_MAX   (18446744073709551615UL)  
  77. # else  
  78. # define UINT_FAST16_MAX   (4294967295U)  
  79. # define UINT_FAST32_MAX   (4294967295U)  
  80. # endif  
  81. # define UINT_FAST64_MAX    (__UINT64_C(18446744073709551615))  
  82.   
  83.   
  84. /* Values to test for integral types holding `void *' pointer. */  
  85. # if __WORDSIZE == 64  
  86. # define INTPTR_MIN        (-9223372036854775807L-1)  
  87. # define INTPTR_MAX        (9223372036854775807L)  
  88. # define UINTPTR_MAX       (18446744073709551615UL)  
  89. # else  
  90. # define INTPTR_MIN        (-2147483647-1)  
  91. # define INTPTR_MAX        (2147483647)  
  92. # define UINTPTR_MAX       (4294967295U)  
  93. # endif  
  94.   
  95.   
  96. /* Minimum for largest signed integral type. */  
  97. # define INTMAX_MIN     (-__INT64_C(9223372036854775807)-1)  
  98. /* Maximum for largest signed integral type. */  
  99. # define INTMAX_MAX     (__INT64_C(9223372036854775807))  
  100.   
  101. /* Maximum for largest unsigned integral type. */  
  102. # define UINTMAX_MAX        (__UINT64_C(18446744073709551615))  
  103.   
  104.   
  105. /* Limits of other integer types. */  
  106.   
  107. /* Limits of `ptrdiff_t' type. */  
  108. # if __WORDSIZE == 64  
  109. # define PTRDIFF_MIN       (-9223372036854775807L-1)  
  110. # define PTRDIFF_MAX       (9223372036854775807L)  
  111. # else  
  112. # define PTRDIFF_MIN       (-2147483647-1)  
  113. # define PTRDIFF_MAX       (2147483647)  
  114. # endif  
  115.   
  116. /* Limits of `sig_atomic_t'. */  
  117. # define SIG_ATOMIC_MIN     (-2147483647-1)  
  118. # define SIG_ATOMIC_MAX     (2147483647)  
  119.   
  120. /* Limit of `size_t' type. */  
  121. # if __WORDSIZE == 64  
  122. # define SIZE_MAX      (18446744073709551615UL)  
  123. # else  
  124. # define SIZE_MAX      (4294967295U)  
  125. # endif  
  126.   
  127. /* Limits of `wchar_t'. */  
  128. # ifndef WCHAR_MIN  
  129. /* These constants might also be defined in <wchar.h>. */  
  130. # define WCHAR_MIN     __WCHAR_MIN  
  131. # define WCHAR_MAX     __WCHAR_MAX  
  132. # endif  
  133.   
  134. /* Limits of `wint_t'. */  
  135. # define WINT_MIN       (0u)  
  136. # define WINT_MAX       (4294967295u)  
  137.   
  138. #endif /* C++ && limit macros */  
  139.   
  140.   
  141. /* The ISO C99 standard specifies that in C++ implementations these 
  142. should only be defined if explicitly requested. */  
  143. #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS  
  144.   
  145. /* Signed. */  
  146. # define INT8_C(c) c  
  147. # define INT16_C(c) c  
  148. # define INT32_C(c) c  
  149. # if __WORDSIZE == 64  
  150. # define INT64_C(c)    c ## L  
  151. # else  
  152. # define INT64_C(c)    c ## LL  
  153. # endif  
  154.   
  155. /* Unsigned. */  
  156. # define UINT8_C(c) c ## U  
  157. # define UINT16_C(c)    c ## U  
  158. # define UINT32_C(c)    c ## U  
  159. # if __WORDSIZE == 64  
  160. # define UINT64_C(c)   c ## UL  
  161. # else  
  162. # define UINT64_C(c)   c ## ULL  
  163. # endif  
  164.   
  165. /* Maximal type. */  
  166. # if __WORDSIZE == 64  
  167. # define INTMAX_C(c)   c ## L  
  168. # define UINTMAX_C(c) c ## UL  
  169. # else  
  170. # define INTMAX_C(c)   c ## LL  
  171. # define UINTMAX_C(c) c ## ULL  
  172. # endif  
  173.   
  174. #endif /* C++ && constant macros */  
  175.   
  176. #endif /* stdint.h */  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值