mirror of
https://github.com/boostorg/integer.git
synced 2025-06-26 20:41:33 +02:00
Compare commits
1 Commits
boost-1.20
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
f4d0cf99ad |
@ -12,10 +12,11 @@
|
||||
<h1><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" align="center" width="277" height="86">Header
|
||||
boost/cstdint.hpp </h1>
|
||||
<p>The header <code><a href="../../boost/cstdint.hpp"><boost/cstdint.hpp></a></code>
|
||||
provides the typedef's useful for
|
||||
writing portable code that requires certain integer widths. All typedef's are in namespace boost.</p>
|
||||
places the contents of the header <code><a href="../../boost/stdint.h"><boost/stdint.h></a></code>
|
||||
in namespace boost. That header consists entirely of typedef's useful for
|
||||
writing portable code that requires certain integer widths.</p>
|
||||
<p>The specifications are based on the ISO/IEC 9899:1999 C Language standard
|
||||
header <stdint.h>. The 64-bit types required by the C standard are not
|
||||
header stdint.h. The 64-bit types required by the C standard are not
|
||||
required in the boost header, and may not be supplied in all implementations,
|
||||
because <code>long long</code> is not [yet] included in the C++ standard.</p>
|
||||
<p>See <a href="cstdint_test.cpp">cstdint_test.cpp</a> for a test program.</p>
|
||||
@ -69,7 +70,7 @@ representing any value of any signed integer type.</p>
|
||||
capable of representing any value of any unsigned integer type.</p>
|
||||
<p>These types are required.</p>
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->14 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15241" -->
|
||||
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->29 Jun 2000<!--webbot bot="Timestamp" endspan i-checksum="15060" -->
|
||||
</p>
|
||||
<p> </p>
|
||||
|
||||
|
227
cstdint_test.cpp
227
cstdint_test.cpp
@ -9,219 +9,66 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||
// 28 Jun 00 Initial version
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <boost/cstdint.hpp>
|
||||
//
|
||||
// macros should not be defined by default:
|
||||
//
|
||||
#ifdef INT8_C
|
||||
#error header incorrectly implemented
|
||||
#endif
|
||||
//
|
||||
// now define the macros:
|
||||
//
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
// the following class is designed to verify
|
||||
// that the various INTXX_C macros can be used
|
||||
// in integral constant expressions:
|
||||
//
|
||||
struct integral_constant_checker
|
||||
{
|
||||
static const boost::int8_t int8 = INT8_C(-127);
|
||||
static const boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
static const boost::uint8_t uint8 = UINT8_C(255);
|
||||
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
static const boost::int16_t int16 = INT16_C(-32767);
|
||||
static const boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
static const boost::uint16_t uint16 = UINT16_C(65535);
|
||||
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
static const boost::int32_t int32 = INT32_C(-2147483647);
|
||||
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
static const boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
static void check();
|
||||
};
|
||||
|
||||
void integral_constant_checker::check()
|
||||
{
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255u );
|
||||
assert( uint_least8 == 255u );
|
||||
assert( uint_fast8 == 255u );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535u );
|
||||
assert( uint_least16 == 65535u );
|
||||
assert( uint_fast16 == 65535u );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295u );
|
||||
assert( uint_least32 == 4294967295u );
|
||||
assert( uint_fast32 == 4294967295u );
|
||||
}
|
||||
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
|
||||
//
|
||||
// the following function simply verifies that the type
|
||||
// of an integral constant is correctly defined:
|
||||
//
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option -w-8008
|
||||
#pragma option -w-8066
|
||||
#endif
|
||||
template <class T1, class T2>
|
||||
void integral_constant_type_check(T1, T2)
|
||||
{
|
||||
//
|
||||
// the types T1 and T2 may not be exactly
|
||||
// the same type, but they should be the
|
||||
// same size and signedness. We could use
|
||||
// numeric_limits to verify this, but
|
||||
// numeric_limits implementations currently
|
||||
// vary too much, or are incomplete or missing.
|
||||
//
|
||||
assert(sizeof(T1) == sizeof(T2));
|
||||
T1 t1 = -1;
|
||||
T2 t2 = -1;
|
||||
assert(t1 == t2);
|
||||
if(t1 >= 0)
|
||||
assert(t2 >= 0);
|
||||
else
|
||||
assert(t2 < 0);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
integral_constant_checker::check();
|
||||
#endif
|
||||
//
|
||||
// verify the types of the integral constants:
|
||||
//
|
||||
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
|
||||
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
|
||||
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
|
||||
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
|
||||
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
|
||||
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
|
||||
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
|
||||
#endif
|
||||
//
|
||||
boost::int8_t int8 = INT8_C(-127);
|
||||
boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
boost::int8_t int8 = -127;
|
||||
boost::int_least8_t int_least8 = -127;
|
||||
boost::int_fast8_t int_fast8 = -127;
|
||||
|
||||
boost::uint8_t uint8 = UINT8_C(255);
|
||||
boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
boost::uint8_t uint8 = 255;
|
||||
boost::uint_least8_t uint_least8 = 255;
|
||||
boost::uint_fast8_t uint_fast8 = 255;
|
||||
|
||||
boost::int16_t int16 = -32767;
|
||||
boost::int_least16_t int_least16 = -32767;
|
||||
boost::int_fast16_t int_fast16 = -32767;
|
||||
|
||||
boost::uint16_t uint16 = 65535;
|
||||
boost::uint_least16_t uint_least16 = 65535;
|
||||
boost::uint_fast16_t uint_fast16 = 65535;
|
||||
|
||||
boost::int32_t int32 = -2147483647;
|
||||
boost::int_least32_t int_least32 = -2147483647;
|
||||
boost::int_fast32_t int_fast32 = -2147483647;
|
||||
|
||||
boost::uint32_t uint32 = 4294967295;
|
||||
boost::uint_least32_t uint_least32 = 4294967295;
|
||||
boost::uint_fast32_t uint_fast32 = 4294967295;
|
||||
|
||||
boost::int16_t int16 = INT16_C(-32767);
|
||||
boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
boost::uint16_t uint16 = UINT16_C(65535);
|
||||
boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
boost::int32_t int32 = INT32_C(-2147483647);
|
||||
boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t int64 = INT64_C(-9223372036854775807);
|
||||
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
|
||||
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
|
||||
|
||||
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
|
||||
|
||||
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
|
||||
#else
|
||||
boost::intmax_t intmax = INTMAX_C(-2147483647);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
|
||||
#endif
|
||||
boost::intmax_t intmax = -2147483647;
|
||||
boost::uintmax_t uintmax = 4294967295;
|
||||
|
||||
assert( int8 == -127 );
|
||||
assert( int_least8 == -127 );
|
||||
assert( int_fast8 == -127 );
|
||||
assert( uint8 == 255u );
|
||||
assert( uint_least8 == 255u );
|
||||
assert( uint_fast8 == 255u );
|
||||
assert( uint8 == 255 );
|
||||
assert( uint_least8 == 255 );
|
||||
assert( uint_fast8 == 255 );
|
||||
assert( int16 == -32767 );
|
||||
assert( int_least16 == -32767 );
|
||||
assert( int_fast16 == -32767 );
|
||||
assert( uint16 == 65535u );
|
||||
assert( uint_least16 == 65535u );
|
||||
assert( uint_fast16 == 65535u );
|
||||
assert( uint16 == 65535 );
|
||||
assert( uint_least16 == 65535 );
|
||||
assert( uint_fast16 == 65535 );
|
||||
assert( int32 == -2147483647 );
|
||||
assert( int_least32 == -2147483647 );
|
||||
assert( int_fast32 == -2147483647 );
|
||||
assert( uint32 == 4294967295u );
|
||||
assert( uint_least32 == 4294967295u );
|
||||
assert( uint_fast32 == 4294967295u );
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
assert( int64 == INT64_C(-9223372036854775807) );
|
||||
assert( int_least64 == INT64_C(-9223372036854775807) );
|
||||
assert( int_fast64 == INT64_C(-9223372036854775807) );
|
||||
assert( uint64 == UINT64_C(18446744073709551615) );
|
||||
assert( uint_least64 == UINT64_C(18446744073709551615) );
|
||||
assert( uint_fast64 == UINT64_C(18446744073709551615) );
|
||||
assert( intmax == INT64_C(-9223372036854775807) );
|
||||
assert( uintmax == UINT64_C(18446744073709551615) );
|
||||
#else
|
||||
assert( uint32 == 4294967295 );
|
||||
assert( uint_least32 == 4294967295 );
|
||||
assert( uint_fast32 == 4294967295 );
|
||||
assert( intmax == -2147483647 );
|
||||
assert( uintmax == 4294967295u );
|
||||
#endif
|
||||
|
||||
assert( uintmax == 4294967295 );
|
||||
|
||||
std::cout << "OK\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// now verify that constant macros get undef'ed correctly:
|
||||
//
|
||||
#undef __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef INT8_C
|
||||
#error boost/cstdint.hpp not correctly defined
|
||||
#endif
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// boost cstdint.hpp header file ------------------------------------------//
|
||||
// boost cstdint.hpp header file -------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
@ -9,22 +9,15 @@
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
|
||||
// 23 Sep 00 Added INTXX_C macro support (John Maddock).
|
||||
// 22 Sep 00 Better 64-bit support (John Maddock)
|
||||
// 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
|
||||
// 8 Aug 99 Initial version (Beman Dawes)
|
||||
|
||||
// 8 Aug 99 Initial version
|
||||
|
||||
#ifndef BOOST_CSTDINT_HPP
|
||||
#define BOOST_CSTDINT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <limits.h> // implementation artifact; not part of interface
|
||||
|
||||
|
||||
#ifdef BOOST_SYSTEM_HAS_STDINT_H
|
||||
|
||||
# include <stdint.h> // implementation artifact; not part of interface
|
||||
#include <boost/stdint.h>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -50,7 +43,7 @@ namespace boost
|
||||
using ::uint_least32_t;
|
||||
using ::uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
# ifdef ULLONG_MAX
|
||||
|
||||
using ::int64_t;
|
||||
using ::int_least64_t;
|
||||
@ -66,234 +59,5 @@ namespace boost
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#else // BOOST_SYSTEM_HAS_STDINT_H
|
||||
|
||||
|
||||
# include <limits.h> // implementation artifact; not part of interface
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
|
||||
// platforms. For other systems, they will have to be hand tailored.
|
||||
//
|
||||
// Because the fast types are assumed to be the same as the undecorated types,
|
||||
// it may be possible to hand tailor a more efficient implementation. Such
|
||||
// an optimization may be illusionary; on the Intel x86-family 386 on, for
|
||||
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
|
||||
|
||||
// 8-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
typedef signed char int8_t;
|
||||
typedef signed char int_least8_t;
|
||||
typedef signed char int_fast8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 32-bit types -----------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
typedef int int32_t;
|
||||
typedef int int_least32_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned int uint_least32_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
typedef long int32_t;
|
||||
typedef long int_least32_t;
|
||||
typedef long int_fast32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned long uint_least32_t;
|
||||
typedef unsigned long uint_fast32_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
// 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long int64_t;
|
||||
typedef long long int_least64_t;
|
||||
typedef long long int_fast64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
typedef long int64_t;
|
||||
typedef long int_least64_t;
|
||||
typedef long int_fast64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
typedef unsigned long uint_least64_t;
|
||||
typedef unsigned long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
# else // assume no 64-bit integers
|
||||
# define BOOST_NO_INT64_T
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
||||
Macro definition section:
|
||||
|
||||
Define various INTXX_C macros only if
|
||||
__STDC_CONSTANT_MACROS is defined.
|
||||
|
||||
Undefine the macros if __STDC_CONSTANT_MACROS is
|
||||
not defined and the macros are (cf <cassert>).
|
||||
|
||||
Added 23rd September (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
|
||||
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
# if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// Borland/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
# define INT8_C(value) value##i8
|
||||
# define INT16_C(value) value##i16
|
||||
# define INT32_C(value) value##i32
|
||||
# define INT64_C(value) value##i64
|
||||
# ifdef __BORLANDC__
|
||||
// Borland bug: appending ui8 makes the type a signed char
|
||||
# define UINT8_C(value) static_cast<unsigned char>(value##u)
|
||||
# else
|
||||
# define UINT8_C(value) value##ui8
|
||||
# endif
|
||||
# define UINT16_C(value) value##ui16
|
||||
# define UINT32_C(value) value##ui32
|
||||
# define UINT64_C(value) value##ui64
|
||||
# define INTMAX_C(value) value##i64
|
||||
# define UINTMAX_C(value) value##ui64
|
||||
|
||||
# else
|
||||
// do it the old fashioned way:
|
||||
|
||||
// 8-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
# define INT8_C(value) static_cast<boost::int8_t>(value)
|
||||
# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
# define INT16_C(value) static_cast<boost::int16_t>(value)
|
||||
# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 32-bit types -----------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
# define INT32_C(value) value
|
||||
# define UINT32_C(value) value##u
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
# define INT32_C(value) value##L
|
||||
# define UINT32_C(value) value##uL
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
# define INT64_C(value) value##L
|
||||
# define UINT64_C(value) value##uL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef BOOST_NO_INT64_T
|
||||
# define INTMAX_C(value) INT32_C(value)
|
||||
# define UINTMAX_C(value) UINT32_C(value)
|
||||
# else
|
||||
# define INTMAX_C(value) INT64_C(value)
|
||||
# define UINTMAX_C(value) UINT64_C(value)
|
||||
# endif
|
||||
|
||||
# endif // Borland/Microsoft specific width suffixes
|
||||
|
||||
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
|
||||
//
|
||||
// undef all the macros:
|
||||
//
|
||||
# undef INT8_C
|
||||
# undef INT16_C
|
||||
# undef INT32_C
|
||||
# undef INT64_C
|
||||
# undef UINT8_C
|
||||
# undef UINT16_C
|
||||
# undef UINT32_C
|
||||
# undef UINT64_C
|
||||
# undef INTMAX_C
|
||||
# undef UINTMAX_C
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS_DEFINED etc.
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
// boost stdint.h header file ---------------------------------------------//
|
||||
// boost stdint.h header file ---------------------------------------------//
|
||||
|
||||
// (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
|
||||
// and distribute this software is granted provided this copyright
|
||||
@ -8,32 +8,11 @@
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// NOTE WELL: This is an implementation of the ISO C Standard (1999) stdint.h
|
||||
// header. C++ programs are advised to use <boost/cstdint.hpp> rather than
|
||||
// NOTE WELL: C++ programs are advised to use <boost/cstdint.hpp> rather than
|
||||
// this header.
|
||||
|
||||
// NOTE OF OBSOLESCENCE: In general, this header file cannot detect
|
||||
// whether the current translation unit somewhere includes ISO C99
|
||||
// <stdint.h> or not. For example, in case BOOST_SYSTEM_HAS_STDINT_H
|
||||
// is not defined and ISO C99 <stdint.h> has been included before,
|
||||
// this file will re-define ISO C99 reserved file-scope identifiers
|
||||
// such as int8_t (see ISO C99 7.1.3 and 7.18). Defining the macro
|
||||
// BOOST_SYSTEM_HAS_STDINT_H is not sufficient in general, in
|
||||
// particular if a partly conformant <stdint.h> header is available
|
||||
// on the platform, e.g. Comeau C++ with GNU glibc 2.1.2.
|
||||
//
|
||||
// In order to avoid incompatibilities with ISO C99, this header
|
||||
// should not be used at all, and it may be deleted in the future.
|
||||
// C++ programs which require ISO C99 <stdint.h> functionality are
|
||||
// strongly advised to use <boost/cstdint.hpp> instead, which
|
||||
// provides <stdint.h> names in namespace boost, e.g. boost::int8_t.
|
||||
|
||||
|
||||
// Revision History
|
||||
// 12 Nov 00 obsoleted (Jens Maurer)
|
||||
// 23 Sep 00 INTXX_C support added (John Maddock)
|
||||
// 22 Sep 00 64-bit support for Borland & Microsoft compilers (John Maddock)
|
||||
// 8 Aug 99 Initial version (Beman Dawes)
|
||||
// 8 Aug 99 Initial version
|
||||
|
||||
#ifndef BOOST_STDINT_H
|
||||
#define BOOST_STDINT_H
|
||||
@ -45,15 +24,16 @@
|
||||
|
||||
#else
|
||||
|
||||
// This is not a complete implementation of the 1999 C Standard stdint.h
|
||||
// header; it doesn't supply various macros which are not advisable for use in
|
||||
// C++ programs.
|
||||
|
||||
#include <limits.h> // implementation artifact; not part of interface
|
||||
|
||||
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
|
||||
// platforms. For other systems, they will have to be hand tailored.
|
||||
//
|
||||
// Because the fast types are assumed to be the same as the undecorated types,
|
||||
// it may be possible to hand tailor a more efficient implementation. Such
|
||||
// an optimization may be illusionary; on the Intel x86-family 386 on, for
|
||||
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
|
||||
// it may be possible to hand tailor a more efficient implementation.
|
||||
|
||||
// 8-bit types -------------------------------------------------------------//
|
||||
|
||||
@ -65,7 +45,7 @@
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# endif
|
||||
|
||||
// 16-bit types ------------------------------------------------------------//
|
||||
@ -78,7 +58,7 @@
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
@ -98,15 +78,13 @@
|
||||
typedef unsigned long uint_least32_t;
|
||||
typedef unsigned long uint_fast32_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
// 2**64 - 1
|
||||
# ifdef ULLONG_MAX
|
||||
# if ULLONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
typedef long long int64_t;
|
||||
@ -116,7 +94,7 @@
|
||||
typedef unsigned long long uint_least64_t;
|
||||
typedef unsigned long long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
@ -130,143 +108,12 @@
|
||||
typedef unsigned long uint_least64_t;
|
||||
typedef unsigned long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# error defaults not correct; you must hand modify boost/stdint.hpp
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
# else // assume no 64-bit integers
|
||||
#define BOOST_NO_INT64_T
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
#endif // BOOST_SYSTEM_HAS_STDINT_H not defined
|
||||
#endif // BOOST_STDINT_H
|
||||
|
||||
/****************************************************
|
||||
|
||||
Macro definition section:
|
||||
|
||||
Define various INTXX_C macros only if
|
||||
__STDC_CONSTANT_MACROS is defined.
|
||||
|
||||
Undefine the macros if __STDC_CONSTANT_MACROS is
|
||||
not defined and the macros are (cf <cassert>).
|
||||
|
||||
Added 23rd September (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED)
|
||||
#define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
#if (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// Borland/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
#define INT8_C(value) value##i8
|
||||
#define INT16_C(value) value##i16
|
||||
#define INT32_C(value) value##i32
|
||||
#define INT64_C(value) value##i64
|
||||
#ifdef __BORLANDC__
|
||||
// Borland bug: appending ui8 makes the type
|
||||
// a signed char!!!!
|
||||
#define UINT8_C(value) static_cast<unsigned char>(value##u)
|
||||
#else
|
||||
#define UINT8_C(value) value##ui8
|
||||
#endif
|
||||
#define UINT16_C(value) value##ui16
|
||||
#define UINT32_C(value) value##ui32
|
||||
#define UINT64_C(value) value##ui64
|
||||
#define INTMAX_C(value) value##i64
|
||||
#define UINTMAX_C(value) value##ui64
|
||||
|
||||
#else
|
||||
// do it the old fashioned way:
|
||||
// 8-bit types -------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
#define INT8_C(value) static_cast<int8_t>(value)
|
||||
#define UINT8_C(value) static_cast<uint8_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 16-bit types ------------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
#define INT16_C(value) static_cast<int16_t>(value)
|
||||
#define UINT16_C(value) static_cast<uint16_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 32-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
#define INT32_C(value) value
|
||||
#define UINT32_C(value) value##u
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
#define INT32_C(value) value##L
|
||||
#define UINT32_C(value) value##uL
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t -----------------------------------//
|
||||
|
||||
# if (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX)) && !(defined(_WIN32) && defined(__GNUC__))
|
||||
# if(defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615)
|
||||
#define INT64_C(value) value##LL
|
||||
#define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
#define INT64_C(value) value##L
|
||||
#define UINT64_C(value) value##uL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/stdint.h
|
||||
# endif
|
||||
# elif (defined(BOOST_MSVC) && (BOOST_MSVC >= 1100)) || (defined(__BORLANDC__) && (__BORLANDC__ >= 0x520))
|
||||
//
|
||||
// we have Borland/Microsoft __int64:
|
||||
//
|
||||
#define INT64_C(value) value##i64
|
||||
#define UINT64_C(value) value##ui64
|
||||
# endif
|
||||
|
||||
#ifdef BOOST_NO_INT64_T
|
||||
#define INTMAX_C(value) INT32_C(value)
|
||||
#define UINTMAX_C(value) UINT32_C(value)
|
||||
#else
|
||||
#define INTMAX_C(value) INT64_C(value)
|
||||
#define UINTMAX_C(value) UINT64_C(value)
|
||||
#endif
|
||||
|
||||
#endif // Borland/MS specific
|
||||
|
||||
#elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS)
|
||||
//
|
||||
// undef all the macros:
|
||||
//
|
||||
#undef INT8_C
|
||||
#undef INT16_C
|
||||
#undef INT32_C
|
||||
#undef INT64_C
|
||||
#undef UINT8_C
|
||||
#undef UINT16_C
|
||||
#undef UINT32_C
|
||||
#undef UINT64_C
|
||||
#undef INTMAX_C
|
||||
#undef UINTMAX_C
|
||||
|
||||
#endif // constant macros
|
||||
|
||||
|
||||
|
42
index.htm
42
index.htm
@ -14,8 +14,8 @@
|
||||
<tr>
|
||||
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home </big></font></a></td>
|
||||
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||
<td><a href="../../people/people.htm"><font face="Arial" color="#FFFFFF"><big>People </big></font></a></td>
|
||||
<td><a href="../../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries </big></font></a></td>
|
||||
<td><a href="../../people.htm"><font face="Arial" color="#FFFFFF"><big>People </big></font></a></td>
|
||||
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ </big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More </big></font></a></td>
|
||||
</tr>
|
||||
@ -34,12 +34,19 @@
|
||||
</a></code><a href="cstdint.htm"><br>
|
||||
documentation</a>
|
||||
</td>
|
||||
<td valign="top">Typedef's based on the 1999 C Standard header <<code>stdint.h></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler
|
||||
supplied <<code>stdint.h></code>, if present. </td>
|
||||
<td valign="top">Contents of <code><boost/stdint.h></code> wrapped in namespace boost.</td>
|
||||
<td valign="top">Supplies typedefs for standard integer types such as <code> int32_t</code> or <code>uint_least16_t</code>.
|
||||
Use in preference to <<code>stdint.h></code>
|
||||
for enhanced portability. Furthermore, all names are safely placed in the boost namespace.</td>
|
||||
Use in preference to <<code>stdint.h></code> or<code> <boost/stdint.h></code>
|
||||
because the names are safely placed in the boost namespace.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/stdint.h"><boost/stdint.h></a></code></td>
|
||||
<td valign="top">Typedefs as defined in the C99 standard header <<code>stdint.h></code>.
|
||||
This implementation #includes the compiler
|
||||
supplied <<code>stdint.h></code>, if present.</td>
|
||||
<td valign="top"> Supplied
|
||||
for use in the implementation of <boost/cstdint.hpp> and to ease transition to the C99 standard.
|
||||
Other uses are not recommended because this header places its names in the global namespace. </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center"><code><a href="../../boost/integer_traits.hpp"><boost/integer_traits.hpp></a></code><br>
|
||||
@ -63,16 +70,17 @@
|
||||
|
||||
<h2>Rationale</h2>
|
||||
<p>The organization of boost integer headers and classes is designed to take
|
||||
advantage of <code><stdint.h></code> types from the 1999 C standard
|
||||
advantage of <code><stdint.h></code> types from in the 1999 C standard
|
||||
without resorting to undefined behavior in terms of
|
||||
the 1998 C++ standard. The header <code><boost/cstdint.hpp></code>
|
||||
makes the standard integer types safely available in namespace boost without placing any names in namespace std. As always, the intension is to complement rather than
|
||||
makes the standard integer types safely available in namespace boost without placing any names in the
|
||||
global namespace or namespace std. As always, the intension is to complement rather than
|
||||
compete with the C++ Standard Library. Should some future C++ standard
|
||||
include <code><stdint.h></code> and <code><cstdint></code>, then <code><boost/cstdint.hpp></code>
|
||||
include <code><stdint.h></code> and <code><cstdint></code>, then <code><boost/stdint.h></code> and <code><boost/cstdint.hpp></code>
|
||||
will continue to function, but will become redundant and may be safely deprecated.</p>
|
||||
<p>Because these are boost headers, their names conform to boost header naming
|
||||
conventions rather than C++ Standard Library header naming conventions.
|
||||
|
||||
conventions rather than C++ Standard Library header naming conventions. An
|
||||
exception is <code><boost/stdint.h> </code>which uses a <b> .h</b> extension to indicate its C rather than C++ heritage.</p>
|
||||
<h2>Caveat emptor</h2>
|
||||
<p>As an
|
||||
implementation artifact, certain C <limits.h> macro names may possibly be
|
||||
@ -80,17 +88,9 @@ visible to users of <boost/cstdint.hpp>. Don't use these macros; the
|
||||
any Boost specified interface.
|
||||
Use boost:: integer_traits<> or std::numeric_limits<> instead.</p>
|
||||
|
||||
<p>
|
||||
As another implementation artifact, certain C
|
||||
<code><stdint.h></code> typedef names may possibly be visible in the
|
||||
global namespace to users of <code><boost/cstdint.hpp></code>.
|
||||
Don't use these names, they are not part of any Boost specified
|
||||
interface. Use the respective names in namespace <code>boost</code>
|
||||
instead.
|
||||
|
||||
<hr>
|
||||
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->14 Nov 2000<!--webbot bot="Timestamp" endspan i-checksum="15241" -->
|
||||
<p>Revised: <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %b %Y" startspan -->05 Mar 2000<!--webbot bot="Timestamp" endspan i-checksum="14882" -->
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
@ -173,4 +173,4 @@ int main()
|
||||
std::cout << 0 << ' '; test( uint_t<0>::fast() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -20,13 +20,14 @@
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <boost/integer_traits.hpp>
|
||||
// use int64_t instead of long long for better portability
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error This test relies on assert() and thus makes no sense with NDEBUG defined
|
||||
#endif
|
||||
|
||||
// enable if you have "long long" and the proper macros in <limits.h>
|
||||
#undef HAVE_LONG_LONG
|
||||
|
||||
|
||||
/*
|
||||
* General portability note:
|
||||
@ -70,11 +71,11 @@ int main()
|
||||
runtest("long", long());
|
||||
typedef unsigned long unsigned_long;
|
||||
runtest("unsigned long", unsigned_long());
|
||||
#if !defined(BOOST_NO_INT64_T) && !defined(BOOST_MSVC) && !defined(__BORLANDC__)
|
||||
//
|
||||
// MS/Borland compilers can't support 64-bit member constants
|
||||
runtest("int64_t (possibly long long)", boost::int64_t());
|
||||
runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
|
||||
#ifdef HAVE_LONG_LONG
|
||||
typedef long long long_long;
|
||||
runtest("long long", long_long());
|
||||
typedef unsigned long long unsigned_long_long;
|
||||
runtest("unsigned long long", unsigned_long_long());
|
||||
#endif
|
||||
// Some compilers don't pay attention to std:3.6.1/5 and issue a
|
||||
// warning here if "return 0;" is omitted.
|
||||
|
Reference in New Issue
Block a user