23
23
#ifndef BOOST_CSTDINT_HPP
24
24
#define BOOST_CSTDINT_HPP
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.
32
#ifndef __STDC_CONSTANT_MACROS
33
# define __STDC_CONSTANT_MACROS
26
36
#include <boost/config.hpp>
29
#ifdef BOOST_HAS_STDINT_H
39
// Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
40
// depending upon what headers happen to have been included first...
41
// so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
42
// See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
44
#if defined(BOOST_HAS_STDINT_H) && (!defined(__GLIBC__) || defined(__GLIBC_HAVE_LONG_LONG))
31
46
// The following #include is an implementation artifact; not part of interface.
326
359
Macro definition section:
328
Define various INTXX_C macros only if
329
__STDC_CONSTANT_MACROS is defined.
331
Undefine the macros if __STDC_CONSTANT_MACROS is
332
not defined and the macros are (cf <cassert>).
334
361
Added 23rd September 2000 (John Maddock).
335
362
Modified 11th September 2001 to be excluded when
336
363
BOOST_HAS_STDINT_H is defined (John Maddock).
364
Modified 11th Dec 2009 to always define the
365
INT#_C macros if they're not already defined (John Maddock).
338
367
******************************************************/
340
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
369
#if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && \
370
(!defined(INT8_C) || !defined(INT16_C) || !defined(INT32_C) || !defined(INT64_C))
372
// For the following code we get several warnings along the lines of:
374
// boost/cstdint.hpp:428:35: error: use of C99 long long integer constant
376
// So we declare this a system header to suppress these warnings.
378
#if defined(__GNUC__) && (__GNUC__ >= 4)
379
#pragma GCC system_header
341
383
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
342
384
# if defined(BOOST_HAS_MS_INT64)
344
386
// Borland/Intel/Microsoft compilers have width specific suffixes:
346
389
# define INT8_C(value) value##i8
347
392
# define INT16_C(value) value##i16
348
395
# define INT32_C(value) value##i32
349
398
# define INT64_C(value) value##i64
350
400
# ifdef __BORLANDC__
351
401
// Borland bug: appending ui8 makes the type a signed char
352
402
# define UINT8_C(value) static_cast<unsigned char>(value##u)
354
404
# define UINT8_C(value) value##ui8
356
407
# define UINT16_C(value) value##ui16
357
410
# define UINT32_C(value) value##ui32
358
413
# define UINT64_C(value) value##ui64
359
416
# define INTMAX_C(value) value##i64
360
417
# define UINTMAX_C(value) value##ui64
363
421
// do it the old fashioned way:
365
423
// 8-bit types ------------------------------------------------------------//
367
# if UCHAR_MAX == 0xff
425
# if (UCHAR_MAX == 0xff) && !defined(INT8_C)
368
426
# define INT8_C(value) static_cast<boost::int8_t>(value)
369
427
# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
372
430
// 16-bit types -----------------------------------------------------------//
374
# if USHRT_MAX == 0xffff
432
# if (USHRT_MAX == 0xffff) && !defined(INT16_C)
375
433
# define INT16_C(value) static_cast<boost::int16_t>(value)
376
434
# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
379
437
// 32-bit types -----------------------------------------------------------//
381
# if UINT_MAX == 0xffffffff
439
# if (UINT_MAX == 0xffffffff)
382
440
# define INT32_C(value) value
383
441
# define UINT32_C(value) value##u
384
442
# elif ULONG_MAX == 0xffffffff
385
443
# define INT32_C(value) value##L
386
444
# define UINT32_C(value) value##uL
389
448
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
391
450
# if defined(BOOST_HAS_LONG_LONG) && \
392
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
451
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_LLONG_MAX))
394
453
# if defined(__hpux)
395
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
396
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) || \
397
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) || \
398
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
454
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
455
# define INT64_C(value) value##LL
456
# define UINT64_C(value) value##uLL
457
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \
458
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \
459
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
460
(defined(_LLONG_MAX) && _LLONG_MAX == 18446744073709551615ULL)
462
# define INT64_C(value) value##LL
463
# define UINT64_C(value) value##uLL
401
465
# error defaults not correct; you must hand modify boost/cstdint.hpp
403
# define INT64_C(value) value##LL
404
# define UINT64_C(value) value##uLL
405
467
# elif ULONG_MAX != 0xffffffff
407
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
469
# if ULONG_MAX == 18446744073709551615U // 2**64 - 1
408
470
# define INT64_C(value) value##L
409
471
# define UINT64_C(value) value##uL
411
473
# error defaults not correct; you must hand modify boost/cstdint.hpp
475
# elif defined(BOOST_HAS_LONG_LONG)
476
// Usual macros not defined, work things out for ourselves:
477
# if(~0uLL == 18446744073709551615ULL)
478
# define INT64_C(value) value##LL
479
# define UINT64_C(value) value##uLL
481
# error defaults not correct; you must hand modify boost/cstdint.hpp
484
# error defaults not correct; you must hand modify boost/cstdint.hpp
415
487
# ifdef BOOST_NO_INT64_T