1// boost cstdint.hpp header file ------------------------------------------//
2
3// (C) Copyright Beman Dawes 1999.
4// (C) Copyright Jens Mauer 2001
5// (C) Copyright John Maddock 2001
6// Distributed under the Boost
7// Software License, Version 1.0. (See accompanying file
8// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10// See http://www.boost.org/libs/integer for documentation.
11
12// Revision History
13// 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
14// 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
15// 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
16// 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
17// 23 Sep 00 Added INTXX_C macro support (John Maddock).
18// 22 Sep 00 Better 64-bit support (John Maddock)
19// 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
20// 8 Aug 99 Initial version (Beman Dawes)
21
22
23#ifndef BOOST_CSTDINT_HPP
24#define BOOST_CSTDINT_HPP
25
26//
27// Since we always define the INT#_C macros as per C++0x,
28// define __STDC_CONSTANT_MACROS so that <stdint.h> does the right
29// thing if possible, and so that the user knows that the macros
30// are actually defined as per C99.
31//
32#ifndef __STDC_CONSTANT_MACROS
33# define __STDC_CONSTANT_MACROS
34#endif
35
36#include <boost/config.hpp>
37//
38// For the following code we get several warnings along the lines of:
39//
40// boost/cstdint.hpp:428:35: error: use of C99 long long integer constant
41//
42// So we declare this a system header to suppress these warnings.
43// See also https://github.com/boostorg/config/issues/190
44//
45#if defined(__GNUC__) && (__GNUC__ >= 4)
46#pragma GCC system_header
47#endif
48
49//
50// Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
51// depending upon what headers happen to have been included first...
52// so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
53// See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
54//
55#if defined(BOOST_HAS_STDINT_H) \
56 && (!defined(__GLIBC__) \
57 || defined(__GLIBC_HAVE_LONG_LONG) \
58 || (defined(__GLIBC__) && ((__GLIBC__ > 2) || ((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 17)))))
59
60// The following #include is an implementation artifact; not part of interface.
61# ifdef __hpux
62// HP-UX has a vaguely nice <stdint.h> in a non-standard location
63# include <inttypes.h>
64# ifdef __STDC_32_MODE__
65 // this is triggered with GCC, because it defines __cplusplus < 199707L
66# define BOOST_NO_INT64_T
67# endif
68# elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
69# include <inttypes.h>
70# else
71# include <stdint.h>
72
73// There is a bug in Cygwin two _C macros
74# if defined(INTMAX_C) && defined(__CYGWIN__)
75# undef INTMAX_C
76# undef UINTMAX_C
77# define INTMAX_C(c) c##LL
78# define UINTMAX_C(c) c##ULL
79# endif
80
81# endif
82
83#if defined(__QNX__) && defined(__EXT_QNX)
84
85// QNX (Dinkumware stdlib) defines these as non-standard names.
86// Reflect to the standard names.
87
88typedef ::intleast8_t int_least8_t;
89typedef ::intfast8_t int_fast8_t;
90typedef ::uintleast8_t uint_least8_t;
91typedef ::uintfast8_t uint_fast8_t;
92
93typedef ::intleast16_t int_least16_t;
94typedef ::intfast16_t int_fast16_t;
95typedef ::uintleast16_t uint_least16_t;
96typedef ::uintfast16_t uint_fast16_t;
97
98typedef ::intleast32_t int_least32_t;
99typedef ::intfast32_t int_fast32_t;
100typedef ::uintleast32_t uint_least32_t;
101typedef ::uintfast32_t uint_fast32_t;
102
103# ifndef BOOST_NO_INT64_T
104
105typedef ::intleast64_t int_least64_t;
106typedef ::intfast64_t int_fast64_t;
107typedef ::uintleast64_t uint_least64_t;
108typedef ::uintfast64_t uint_fast64_t;
109
110# endif
111
112#endif
113
114namespace boost
115{
116
117 using ::int8_t;
118 using ::int_least8_t;
119 using ::int_fast8_t;
120 using ::uint8_t;
121 using ::uint_least8_t;
122 using ::uint_fast8_t;
123
124 using ::int16_t;
125 using ::int_least16_t;
126 using ::int_fast16_t;
127 using ::uint16_t;
128 using ::uint_least16_t;
129 using ::uint_fast16_t;
130
131 using ::int32_t;
132 using ::int_least32_t;
133 using ::int_fast32_t;
134 using ::uint32_t;
135 using ::uint_least32_t;
136 using ::uint_fast32_t;
137
138# ifndef BOOST_NO_INT64_T
139
140 using ::int64_t;
141 using ::int_least64_t;
142 using ::int_fast64_t;
143 using ::uint64_t;
144 using ::uint_least64_t;
145 using ::uint_fast64_t;
146
147# endif
148
149 using ::intmax_t;
150 using ::uintmax_t;
151
152} // namespace boost
153
154#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__) || defined(__VMS) || defined(__SOLARIS9__) || defined(__NetBSD__)
155// FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
156# include <inttypes.h>
157
158namespace boost {
159
160 using ::int8_t;
161 typedef int8_t int_least8_t;
162 typedef int8_t int_fast8_t;
163 using ::uint8_t;
164 typedef uint8_t uint_least8_t;
165 typedef uint8_t uint_fast8_t;
166
167 using ::int16_t;
168 typedef int16_t int_least16_t;
169 typedef int16_t int_fast16_t;
170 using ::uint16_t;
171 typedef uint16_t uint_least16_t;
172 typedef uint16_t uint_fast16_t;
173
174 using ::int32_t;
175 typedef int32_t int_least32_t;
176 typedef int32_t int_fast32_t;
177 using ::uint32_t;
178 typedef uint32_t uint_least32_t;
179 typedef uint32_t uint_fast32_t;
180
181# ifndef BOOST_NO_INT64_T
182
183 using ::int64_t;
184 typedef int64_t int_least64_t;
185 typedef int64_t int_fast64_t;
186 using ::uint64_t;
187 typedef uint64_t uint_least64_t;
188 typedef uint64_t uint_fast64_t;
189
190 typedef int64_t intmax_t;
191 typedef uint64_t uintmax_t;
192
193# else
194
195 typedef int32_t intmax_t;
196 typedef uint32_t uintmax_t;
197
198# endif
199
200} // namespace boost
201
202#else // BOOST_HAS_STDINT_H
203
204# include <boost/limits.hpp> // implementation artifact; not part of interface
205# include <limits.h> // needed for limits macros
206
207
208namespace boost
209{
210
211// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
212// platforms. For other systems, they will have to be hand tailored.
213//
214// Because the fast types are assumed to be the same as the undecorated types,
215// it may be possible to hand tailor a more efficient implementation. Such
216// an optimization may be illusionary; on the Intel x86-family 386 on, for
217// example, byte arithmetic and load/stores are as fast as "int" sized ones.
218
219// 8-bit types ------------------------------------------------------------//
220
221# if UCHAR_MAX == 0xff
222 typedef signed char int8_t;
223 typedef signed char int_least8_t;
224 typedef signed char int_fast8_t;
225 typedef unsigned char uint8_t;
226 typedef unsigned char uint_least8_t;
227 typedef unsigned char uint_fast8_t;
228# else
229# error defaults not correct; you must hand modify boost/cstdint.hpp
230# endif
231
232// 16-bit types -----------------------------------------------------------//
233
234# if USHRT_MAX == 0xffff
235# if defined(__crayx1)
236 // The Cray X1 has a 16-bit short, however it is not recommend
237 // for use in performance critical code.
238 typedef short int16_t;
239 typedef short int_least16_t;
240 typedef int int_fast16_t;
241 typedef unsigned short uint16_t;
242 typedef unsigned short uint_least16_t;
243 typedef unsigned int uint_fast16_t;
244# else
245 typedef short int16_t;
246 typedef short int_least16_t;
247 typedef short int_fast16_t;
248 typedef unsigned short uint16_t;
249 typedef unsigned short uint_least16_t;
250 typedef unsigned short uint_fast16_t;
251# endif
252# elif (USHRT_MAX == 0xffffffff) && defined(__MTA__)
253 // On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified
254 // MTA / XMT does support the following non-standard integer types
255 typedef __short16 int16_t;
256 typedef __short16 int_least16_t;
257 typedef __short16 int_fast16_t;
258 typedef unsigned __short16 uint16_t;
259 typedef unsigned __short16 uint_least16_t;
260 typedef unsigned __short16 uint_fast16_t;
261# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
262 // no 16-bit types on Cray:
263 typedef short int_least16_t;
264 typedef short int_fast16_t;
265 typedef unsigned short uint_least16_t;
266 typedef unsigned short uint_fast16_t;
267# else
268# error defaults not correct; you must hand modify boost/cstdint.hpp
269# endif
270
271// 32-bit types -----------------------------------------------------------//
272
273# if UINT_MAX == 0xffffffff
274 typedef int int32_t;
275 typedef int int_least32_t;
276 typedef int int_fast32_t;
277 typedef unsigned int uint32_t;
278 typedef unsigned int uint_least32_t;
279 typedef unsigned int uint_fast32_t;
280# elif (USHRT_MAX == 0xffffffff)
281 typedef short int32_t;
282 typedef short int_least32_t;
283 typedef short int_fast32_t;
284 typedef unsigned short uint32_t;
285 typedef unsigned short uint_least32_t;
286 typedef unsigned short uint_fast32_t;
287# elif ULONG_MAX == 0xffffffff
288 typedef long int32_t;
289 typedef long int_least32_t;
290 typedef long int_fast32_t;
291 typedef unsigned long uint32_t;
292 typedef unsigned long uint_least32_t;
293 typedef unsigned long uint_fast32_t;
294# elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__)
295 // Integers are 64 bits on the MTA / XMT
296 typedef __int32 int32_t;
297 typedef __int32 int_least32_t;
298 typedef __int32 int_fast32_t;
299 typedef unsigned __int32 uint32_t;
300 typedef unsigned __int32 uint_least32_t;
301 typedef unsigned __int32 uint_fast32_t;
302# else
303# error defaults not correct; you must hand modify boost/cstdint.hpp
304# endif
305
306// 64-bit types + intmax_t and uintmax_t ----------------------------------//
307
308# if defined(BOOST_HAS_LONG_LONG) && \
309 !defined(BOOST_MSVC) && !defined(BOOST_BORLANDC) && \
310 (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
311 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
312# if defined(__hpux)
313 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
314# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
315 // 2**64 - 1
316# else
317# error defaults not correct; you must hand modify boost/cstdint.hpp
318# endif
319
320 typedef ::boost::long_long_type intmax_t;
321 typedef ::boost::ulong_long_type uintmax_t;
322 typedef ::boost::long_long_type int64_t;
323 typedef ::boost::long_long_type int_least64_t;
324 typedef ::boost::long_long_type int_fast64_t;
325 typedef ::boost::ulong_long_type uint64_t;
326 typedef ::boost::ulong_long_type uint_least64_t;
327 typedef ::boost::ulong_long_type uint_fast64_t;
328
329# elif ULONG_MAX != 0xffffffff
330
331# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
332 typedef long intmax_t;
333 typedef unsigned long uintmax_t;
334 typedef long int64_t;
335 typedef long int_least64_t;
336 typedef long int_fast64_t;
337 typedef unsigned long uint64_t;
338 typedef unsigned long uint_least64_t;
339 typedef unsigned long uint_fast64_t;
340# else
341# error defaults not correct; you must hand modify boost/cstdint.hpp
342# endif
343# elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
344 __extension__ typedef long long intmax_t;
345 __extension__ typedef unsigned long long uintmax_t;
346 __extension__ typedef long long int64_t;
347 __extension__ typedef long long int_least64_t;
348 __extension__ typedef long long int_fast64_t;
349 __extension__ typedef unsigned long long uint64_t;
350 __extension__ typedef unsigned long long uint_least64_t;
351 __extension__ typedef unsigned long long uint_fast64_t;
352# elif defined(BOOST_HAS_MS_INT64)
353 //
354 // we have Borland/Intel/Microsoft __int64:
355 //
356 typedef __int64 intmax_t;
357 typedef unsigned __int64 uintmax_t;
358 typedef __int64 int64_t;
359 typedef __int64 int_least64_t;
360 typedef __int64 int_fast64_t;
361 typedef unsigned __int64 uint64_t;
362 typedef unsigned __int64 uint_least64_t;
363 typedef unsigned __int64 uint_fast64_t;
364# else // assume no 64-bit integers
365# define BOOST_NO_INT64_T
366 typedef int32_t intmax_t;
367 typedef uint32_t uintmax_t;
368# endif
369
370} // namespace boost
371
372
373#endif // BOOST_HAS_STDINT_H
374
375// intptr_t/uintptr_t are defined separately because they are optional and not universally available
376#if defined(BOOST_WINDOWS) && !defined(_WIN32_WCE) && !defined(BOOST_HAS_STDINT_H)
377// Older MSVC don't have stdint.h and have intptr_t/uintptr_t defined in stddef.h
378#include <stddef.h>
379#endif
380
381#if (defined(BOOST_WINDOWS) && !defined(_WIN32_WCE)) \
382 || (defined(_XOPEN_UNIX) && (_XOPEN_UNIX+0 > 0) && !defined(__UCLIBC__)) \
383 || defined(__CYGWIN__) || defined(__VXWORKS__) \
384 || defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__) \
385 || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || (defined(sun) && !defined(BOOST_HAS_STDINT_H)) || defined(INTPTR_MAX)
386
387namespace boost {
388 using ::intptr_t;
389 using ::uintptr_t;
390}
391#define BOOST_HAS_INTPTR_T
392
393// Clang pretends to be GCC, so it'll match this condition
394#elif defined(__GNUC__) && defined(__INTPTR_TYPE__) && defined(__UINTPTR_TYPE__)
395
396namespace boost {
397 typedef __INTPTR_TYPE__ intptr_t;
398 typedef __UINTPTR_TYPE__ uintptr_t;
399}
400#define BOOST_HAS_INTPTR_T
401
402#endif
403
404#endif // BOOST_CSTDINT_HPP
405
406
407/****************************************************
408
409Macro definition section:
410
411Added 23rd September 2000 (John Maddock).
412Modified 11th September 2001 to be excluded when
413BOOST_HAS_STDINT_H is defined (John Maddock).
414Modified 11th Dec 2009 to always define the
415INT#_C macros if they're not already defined (John Maddock).
416
417******************************************************/
418
419#if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && \
420 (!defined(INT8_C) || !defined(INT16_C) || !defined(INT32_C) || !defined(INT64_C))
421//
422// Undef the macros as a precaution, since we may get here if <stdint.h> has failed
423// to define them all, see https://svn.boost.org/trac/boost/ticket/12786
424//
425#undef INT8_C
426#undef INT16_C
427#undef INT32_C
428#undef INT64_C
429#undef INTMAX_C
430#undef UINT8_C
431#undef UINT16_C
432#undef UINT32_C
433#undef UINT64_C
434#undef UINTMAX_C
435
436#include <limits.h>
437# define BOOST__STDC_CONSTANT_MACROS_DEFINED
438# if defined(BOOST_HAS_MS_INT64)
439//
440// Borland/Intel/Microsoft compilers have width specific suffixes:
441//
442#ifndef INT8_C
443# define INT8_C(value) value##i8
444#endif
445#ifndef INT16_C
446# define INT16_C(value) value##i16
447#endif
448#ifndef INT32_C
449# define INT32_C(value) value##i32
450#endif
451#ifndef INT64_C
452# define INT64_C(value) value##i64
453#endif
454# ifdef BOOST_BORLANDC
455 // Borland bug: appending ui8 makes the type a signed char
456# define UINT8_C(value) static_cast<unsigned char>(value##u)
457# else
458# define UINT8_C(value) value##ui8
459# endif
460#ifndef UINT16_C
461# define UINT16_C(value) value##ui16
462#endif
463#ifndef UINT32_C
464# define UINT32_C(value) value##ui32
465#endif
466#ifndef UINT64_C
467# define UINT64_C(value) value##ui64
468#endif
469#ifndef INTMAX_C
470# define INTMAX_C(value) value##i64
471# define UINTMAX_C(value) value##ui64
472#endif
473
474# else
475// do it the old fashioned way:
476
477// 8-bit types ------------------------------------------------------------//
478
479# if (UCHAR_MAX == 0xff) && !defined(INT8_C)
480# define INT8_C(value) static_cast<boost::int8_t>(value)
481# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
482# endif
483
484// 16-bit types -----------------------------------------------------------//
485
486# if (USHRT_MAX == 0xffff) && !defined(INT16_C)
487# define INT16_C(value) static_cast<boost::int16_t>(value)
488# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
489# endif
490
491// 32-bit types -----------------------------------------------------------//
492#ifndef INT32_C
493# if (UINT_MAX == 0xffffffff)
494# define INT32_C(value) value
495# define UINT32_C(value) value##u
496# elif ULONG_MAX == 0xffffffff
497# define INT32_C(value) value##L
498# define UINT32_C(value) value##uL
499# endif
500#endif
501
502// 64-bit types + intmax_t and uintmax_t ----------------------------------//
503#ifndef INT64_C
504# if defined(BOOST_HAS_LONG_LONG) && \
505 (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_ULLONG_MAX) || defined(_LLONG_MAX))
506
507# if defined(__hpux)
508 // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
509# define INT64_C(value) value##LL
510# define UINT64_C(value) value##uLL
511# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \
512 (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \
513 (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
514 (defined(_ULLONG_MAX) && _ULLONG_MAX == 18446744073709551615ULL) || \
515 (defined(_LLONG_MAX) && _LLONG_MAX == 9223372036854775807LL)
516
517# define INT64_C(value) value##LL
518# define UINT64_C(value) value##uLL
519# else
520# error defaults not correct; you must hand modify boost/cstdint.hpp
521# endif
522# elif ULONG_MAX != 0xffffffff
523
524# if ULONG_MAX == 18446744073709551615U // 2**64 - 1
525# define INT64_C(value) value##L
526# define UINT64_C(value) value##uL
527# else
528# error defaults not correct; you must hand modify boost/cstdint.hpp
529# endif
530# elif defined(BOOST_HAS_LONG_LONG)
531 // Usual macros not defined, work things out for ourselves:
532# if(~0uLL == 18446744073709551615ULL)
533# define INT64_C(value) value##LL
534# define UINT64_C(value) value##uLL
535# else
536# error defaults not correct; you must hand modify boost/cstdint.hpp
537# endif
538# else
539# error defaults not correct; you must hand modify boost/cstdint.hpp
540# endif
541
542# ifdef BOOST_NO_INT64_T
543# define INTMAX_C(value) INT32_C(value)
544# define UINTMAX_C(value) UINT32_C(value)
545# else
546# define INTMAX_C(value) INT64_C(value)
547# define UINTMAX_C(value) UINT64_C(value)
548# endif
549#endif
550# endif // Borland/Microsoft specific width suffixes
551
552#endif // INT#_C macros.
553
554
555
556
557

source code of include/boost/cstdint.hpp