stdint.in.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /* Copyright (C) 2001-2002, 2004-2007 Free Software Foundation, Inc.
  2. Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
  3. This file is part of gnulib.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  15. /*
  16. * ISO C 99 <stdint.h> for platforms that lack it.
  17. * <http://www.opengroup.org/susv3xbd/stdint.h.html>
  18. */
  19. #ifndef _GL_STDINT_H
  20. /* When including a system file that in turn includes <inttypes.h>,
  21. use the system <inttypes.h>, not our substitute. This avoids
  22. problems with (for example) VMS, whose <sys/bitypes.h> includes
  23. <inttypes.h>. */
  24. #define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
  25. /* Get those types that are already defined in other system include
  26. files, so that we can "#define int8_t signed char" below without
  27. worrying about a later system include file containing a "typedef
  28. signed char int8_t;" that will get messed up by our macro. Our
  29. macros should all be consistent with the system versions, except
  30. for the "fast" types and macros, which we recommend against using
  31. in public interfaces due to compiler differences. */
  32. #if @HAVE_STDINT_H@
  33. # if defined __sgi && ! defined __c99
  34. /* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
  35. with "This header file is to be used only for c99 mode compilations"
  36. diagnostics. */
  37. # define __STDINT_H__
  38. # endif
  39. /* Other systems may have an incomplete or buggy <stdint.h>.
  40. Include it before <inttypes.h>, since any "#include <stdint.h>"
  41. in <inttypes.h> would reinclude us, skipping our contents because
  42. _GL_STDINT_H is defined.
  43. The include_next requires a split double-inclusion guard. */
  44. # @INCLUDE_NEXT@ @NEXT_STDINT_H@
  45. #endif
  46. #if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
  47. #define _GL_STDINT_H
  48. /* <sys/types.h> defines some of the stdint.h types as well, on glibc,
  49. IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
  50. AIX 5.2 <sys/types.h> isn't needed and causes troubles.
  51. MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
  52. relies on the system <stdint.h> definitions, so include
  53. <sys/types.h> after @NEXT_STDINT_H@. */
  54. #if @HAVE_SYS_TYPES_H@ && ! defined _AIX
  55. # include <sys/types.h>
  56. #endif
  57. /* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
  58. #include <limits.h>
  59. #if @HAVE_INTTYPES_H@
  60. /* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
  61. int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
  62. <inttypes.h> also defines intptr_t and uintptr_t. */
  63. # include <inttypes.h>
  64. #elif @HAVE_SYS_INTTYPES_H@
  65. /* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
  66. the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
  67. # include <sys/inttypes.h>
  68. #endif
  69. #if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
  70. /* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
  71. int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
  72. included by <sys/types.h>. */
  73. # include <sys/bitypes.h>
  74. #endif
  75. #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
  76. /* Get WCHAR_MIN, WCHAR_MAX. */
  77. # if ! (defined WCHAR_MIN && defined WCHAR_MAX)
  78. # include <wchar.h>
  79. # endif
  80. #endif
  81. #undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
  82. /* Minimum and maximum values for a integer type under the usual assumption.
  83. Return an unspecified value if BITS == 0, adding a check to pacify
  84. picky compilers. */
  85. #define _STDINT_MIN(signed, bits, zero) \
  86. ((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero))
  87. #define _STDINT_MAX(signed, bits, zero) \
  88. ((signed) \
  89. ? ~ _STDINT_MIN (signed, bits, zero) \
  90. : /* The expression for the unsigned case. The subtraction of (signed) \
  91. is a nop in the unsigned case and avoids "signed integer overflow" \
  92. warnings in the signed case. */ \
  93. ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
  94. /* 7.18.1.1. Exact-width integer types */
  95. /* Here we assume a standard architecture where the hardware integer
  96. types have 8, 16, 32, optionally 64 bits. */
  97. #undef int8_t
  98. #undef uint8_t
  99. #define int8_t signed char
  100. #define uint8_t unsigned char
  101. #undef int16_t
  102. #undef uint16_t
  103. #define int16_t short int
  104. #define uint16_t unsigned short int
  105. #undef int32_t
  106. #undef uint32_t
  107. #define int32_t int
  108. #define uint32_t unsigned int
  109. /* Do not undefine int64_t if gnulib is not being used with 64-bit
  110. types, since otherwise it breaks platforms like Tandem/NSK. */
  111. #if LONG_MAX >> 31 >> 31 == 1
  112. # undef int64_t
  113. # define int64_t long int
  114. # define GL_INT64_T
  115. #elif defined _MSC_VER
  116. # undef int64_t
  117. # define int64_t __int64
  118. # define GL_INT64_T
  119. #elif @HAVE_LONG_LONG_INT@
  120. # undef int64_t
  121. # define int64_t long long int
  122. # define GL_INT64_T
  123. #endif
  124. #if ULONG_MAX >> 31 >> 31 >> 1 == 1
  125. # undef uint64_t
  126. # define uint64_t unsigned long int
  127. # define GL_UINT64_T
  128. #elif defined _MSC_VER
  129. # undef uint64_t
  130. # define uint64_t unsigned __int64
  131. # define GL_UINT64_T
  132. #elif @HAVE_UNSIGNED_LONG_LONG_INT@
  133. # undef uint64_t
  134. # define uint64_t unsigned long long int
  135. # define GL_UINT64_T
  136. #endif
  137. /* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
  138. #define _UINT8_T
  139. #define _UINT32_T
  140. #define _UINT64_T
  141. /* 7.18.1.2. Minimum-width integer types */
  142. /* Here we assume a standard architecture where the hardware integer
  143. types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
  144. are the same as the corresponding N_t types. */
  145. #undef int_least8_t
  146. #undef uint_least8_t
  147. #undef int_least16_t
  148. #undef uint_least16_t
  149. #undef int_least32_t
  150. #undef uint_least32_t
  151. #undef int_least64_t
  152. #undef uint_least64_t
  153. #define int_least8_t int8_t
  154. #define uint_least8_t uint8_t
  155. #define int_least16_t int16_t
  156. #define uint_least16_t uint16_t
  157. #define int_least32_t int32_t
  158. #define uint_least32_t uint32_t
  159. #ifdef GL_INT64_T
  160. # define int_least64_t int64_t
  161. #endif
  162. #ifdef GL_UINT64_T
  163. # define uint_least64_t uint64_t
  164. #endif
  165. /* 7.18.1.3. Fastest minimum-width integer types */
  166. /* Note: Other <stdint.h> substitutes may define these types differently.
  167. It is not recommended to use these types in public header files. */
  168. /* Here we assume a standard architecture where the hardware integer
  169. types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
  170. are taken from the same list of types. Assume that 'long int'
  171. is fast enough for all narrower integers. */
  172. #undef int_fast8_t
  173. #undef uint_fast8_t
  174. #undef int_fast16_t
  175. #undef uint_fast16_t
  176. #undef int_fast32_t
  177. #undef uint_fast32_t
  178. #undef int_fast64_t
  179. #undef uint_fast64_t
  180. #define int_fast8_t long int
  181. #define uint_fast8_t unsigned int_fast8_t
  182. #define int_fast16_t long int
  183. #define uint_fast16_t unsigned int_fast16_t
  184. #define int_fast32_t long int
  185. #define uint_fast32_t unsigned int_fast32_t
  186. #ifdef GL_INT64_T
  187. # define int_fast64_t int64_t
  188. #endif
  189. #ifdef GL_UINT64_T
  190. # define uint_fast64_t uint64_t
  191. #endif
  192. /* 7.18.1.4. Integer types capable of holding object pointers */
  193. #undef intptr_t
  194. #undef uintptr_t
  195. #define intptr_t long int
  196. #define uintptr_t unsigned long int
  197. /* 7.18.1.5. Greatest-width integer types */
  198. /* Note: These types are compiler dependent. It may be unwise to use them in
  199. public header files. */
  200. #undef intmax_t
  201. #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
  202. # define intmax_t long long int
  203. #elif defined GL_INT64_T
  204. # define intmax_t int64_t
  205. #else
  206. # define intmax_t long int
  207. #endif
  208. #undef uintmax_t
  209. #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
  210. # define uintmax_t unsigned long long int
  211. #elif defined GL_UINT64_T
  212. # define uintmax_t uint64_t
  213. #else
  214. # define uintmax_t unsigned long int
  215. #endif
  216. /* Verify that intmax_t and uintmax_t have the same size. Too much code
  217. breaks if this is not the case. If this check fails, the reason is likely
  218. to be found in the autoconf macros. */
  219. typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - 1];
  220. /* 7.18.2. Limits of specified-width integer types */
  221. #if ! defined __cplusplus || defined __STDC_LIMIT_MACROS
  222. /* 7.18.2.1. Limits of exact-width integer types */
  223. /* Here we assume a standard architecture where the hardware integer
  224. types have 8, 16, 32, optionally 64 bits. */
  225. #undef INT8_MIN
  226. #undef INT8_MAX
  227. #undef UINT8_MAX
  228. #define INT8_MIN (~ INT8_MAX)
  229. #define INT8_MAX 127
  230. #define UINT8_MAX 255
  231. #undef INT16_MIN
  232. #undef INT16_MAX
  233. #undef UINT16_MAX
  234. #define INT16_MIN (~ INT16_MAX)
  235. #define INT16_MAX 32767
  236. #define UINT16_MAX 65535
  237. #undef INT32_MIN
  238. #undef INT32_MAX
  239. #undef UINT32_MAX
  240. #define INT32_MIN (~ INT32_MAX)
  241. #define INT32_MAX 2147483647
  242. #define UINT32_MAX 4294967295U
  243. #undef INT64_MIN
  244. #undef INT64_MAX
  245. #ifdef GL_INT64_T
  246. /* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
  247. evaluates the latter incorrectly in preprocessor expressions. */
  248. # define INT64_MIN (- INTMAX_C (1) << 63)
  249. # define INT64_MAX INTMAX_C (9223372036854775807)
  250. #endif
  251. #undef UINT64_MAX
  252. #ifdef GL_UINT64_T
  253. # define UINT64_MAX UINTMAX_C (18446744073709551615)
  254. #endif
  255. /* 7.18.2.2. Limits of minimum-width integer types */
  256. /* Here we assume a standard architecture where the hardware integer
  257. types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
  258. are the same as the corresponding N_t types. */
  259. #undef INT_LEAST8_MIN
  260. #undef INT_LEAST8_MAX
  261. #undef UINT_LEAST8_MAX
  262. #define INT_LEAST8_MIN INT8_MIN
  263. #define INT_LEAST8_MAX INT8_MAX
  264. #define UINT_LEAST8_MAX UINT8_MAX
  265. #undef INT_LEAST16_MIN
  266. #undef INT_LEAST16_MAX
  267. #undef UINT_LEAST16_MAX
  268. #define INT_LEAST16_MIN INT16_MIN
  269. #define INT_LEAST16_MAX INT16_MAX
  270. #define UINT_LEAST16_MAX UINT16_MAX
  271. #undef INT_LEAST32_MIN
  272. #undef INT_LEAST32_MAX
  273. #undef UINT_LEAST32_MAX
  274. #define INT_LEAST32_MIN INT32_MIN
  275. #define INT_LEAST32_MAX INT32_MAX
  276. #define UINT_LEAST32_MAX UINT32_MAX
  277. #undef INT_LEAST64_MIN
  278. #undef INT_LEAST64_MAX
  279. #ifdef GL_INT64_T
  280. # define INT_LEAST64_MIN INT64_MIN
  281. # define INT_LEAST64_MAX INT64_MAX
  282. #endif
  283. #undef UINT_LEAST64_MAX
  284. #ifdef GL_UINT64_T
  285. # define UINT_LEAST64_MAX UINT64_MAX
  286. #endif
  287. /* 7.18.2.3. Limits of fastest minimum-width integer types */
  288. /* Here we assume a standard architecture where the hardware integer
  289. types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
  290. are taken from the same list of types. */
  291. #undef INT_FAST8_MIN
  292. #undef INT_FAST8_MAX
  293. #undef UINT_FAST8_MAX
  294. #define INT_FAST8_MIN LONG_MIN
  295. #define INT_FAST8_MAX LONG_MAX
  296. #define UINT_FAST8_MAX ULONG_MAX
  297. #undef INT_FAST16_MIN
  298. #undef INT_FAST16_MAX
  299. #undef UINT_FAST16_MAX
  300. #define INT_FAST16_MIN LONG_MIN
  301. #define INT_FAST16_MAX LONG_MAX
  302. #define UINT_FAST16_MAX ULONG_MAX
  303. #undef INT_FAST32_MIN
  304. #undef INT_FAST32_MAX
  305. #undef UINT_FAST32_MAX
  306. #define INT_FAST32_MIN LONG_MIN
  307. #define INT_FAST32_MAX LONG_MAX
  308. #define UINT_FAST32_MAX ULONG_MAX
  309. #undef INT_FAST64_MIN
  310. #undef INT_FAST64_MAX
  311. #ifdef GL_INT64_T
  312. # define INT_FAST64_MIN INT64_MIN
  313. # define INT_FAST64_MAX INT64_MAX
  314. #endif
  315. #undef UINT_FAST64_MAX
  316. #ifdef GL_UINT64_T
  317. # define UINT_FAST64_MAX UINT64_MAX
  318. #endif
  319. /* 7.18.2.4. Limits of integer types capable of holding object pointers */
  320. #undef INTPTR_MIN
  321. #undef INTPTR_MAX
  322. #undef UINTPTR_MAX
  323. #define INTPTR_MIN LONG_MIN
  324. #define INTPTR_MAX LONG_MAX
  325. #define UINTPTR_MAX ULONG_MAX
  326. /* 7.18.2.5. Limits of greatest-width integer types */
  327. #undef INTMAX_MIN
  328. #undef INTMAX_MAX
  329. #ifdef INT64_MAX
  330. # define INTMAX_MIN INT64_MIN
  331. # define INTMAX_MAX INT64_MAX
  332. #else
  333. # define INTMAX_MIN INT32_MIN
  334. # define INTMAX_MAX INT32_MAX
  335. #endif
  336. #undef UINTMAX_MAX
  337. #ifdef UINT64_MAX
  338. # define UINTMAX_MAX UINT64_MAX
  339. #else
  340. # define UINTMAX_MAX UINT32_MAX
  341. #endif
  342. /* 7.18.3. Limits of other integer types */
  343. /* ptrdiff_t limits */
  344. #undef PTRDIFF_MIN
  345. #undef PTRDIFF_MAX
  346. #define PTRDIFF_MIN \
  347. _STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
  348. #define PTRDIFF_MAX \
  349. _STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
  350. /* sig_atomic_t limits */
  351. #undef SIG_ATOMIC_MIN
  352. #undef SIG_ATOMIC_MAX
  353. #define SIG_ATOMIC_MIN \
  354. _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
  355. 0@SIG_ATOMIC_T_SUFFIX@)
  356. #define SIG_ATOMIC_MAX \
  357. _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
  358. 0@SIG_ATOMIC_T_SUFFIX@)
  359. /* size_t limit */
  360. #undef SIZE_MAX
  361. #define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
  362. /* wchar_t limits */
  363. #undef WCHAR_MIN
  364. #undef WCHAR_MAX
  365. #define WCHAR_MIN \
  366. _STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
  367. #define WCHAR_MAX \
  368. _STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
  369. /* wint_t limits */
  370. #undef WINT_MIN
  371. #undef WINT_MAX
  372. #define WINT_MIN \
  373. _STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
  374. #define WINT_MAX \
  375. _STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
  376. #endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */
  377. /* 7.18.4. Macros for integer constants */
  378. #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
  379. /* 7.18.4.1. Macros for minimum-width integer constants */
  380. /* According to ISO C 99 Technical Corrigendum 1 */
  381. /* Here we assume a standard architecture where the hardware integer
  382. types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
  383. #undef INT8_C
  384. #undef UINT8_C
  385. #define INT8_C(x) x
  386. #define UINT8_C(x) x
  387. #undef INT16_C
  388. #undef UINT16_C
  389. #define INT16_C(x) x
  390. #define UINT16_C(x) x
  391. #undef INT32_C
  392. #undef UINT32_C
  393. #define INT32_C(x) x
  394. #define UINT32_C(x) x ## U
  395. #undef INT64_C
  396. #undef UINT64_C
  397. #if LONG_MAX >> 31 >> 31 == 1
  398. # define INT64_C(x) x##L
  399. #elif defined _MSC_VER
  400. # define INT64_C(x) x##i64
  401. #elif @HAVE_LONG_LONG_INT@
  402. # define INT64_C(x) x##LL
  403. #endif
  404. #if ULONG_MAX >> 31 >> 31 >> 1 == 1
  405. # define UINT64_C(x) x##UL
  406. #elif defined _MSC_VER
  407. # define UINT64_C(x) x##ui64
  408. #elif @HAVE_UNSIGNED_LONG_LONG_INT@
  409. # define UINT64_C(x) x##ULL
  410. #endif
  411. /* 7.18.4.2. Macros for greatest-width integer constants */
  412. #undef INTMAX_C
  413. #if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
  414. # define INTMAX_C(x) x##LL
  415. #elif defined GL_INT64_T
  416. # define INTMAX_C(x) INT64_C(x)
  417. #else
  418. # define INTMAX_C(x) x##L
  419. #endif
  420. #undef UINTMAX_C
  421. #if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
  422. # define UINTMAX_C(x) x##ULL
  423. #elif defined GL_UINT64_T
  424. # define UINTMAX_C(x) UINT64_C(x)
  425. #else
  426. # define UINTMAX_C(x) x##UL
  427. #endif
  428. #endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
  429. #endif /* _GL_STDINT_H */
  430. #endif /* !defined _GL_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */