]> git.lyx.org Git - lyx.git/blob - boost/boost/cstdint.hpp
update from Boost CVS
[lyx.git] / boost / boost / cstdint.hpp
1 //  boost cstdint.hpp header file  ------------------------------------------//
2
3 //  (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
4 //  and distribute this software is granted provided this copyright
5 //  notice appears in all copies. This software is provided "as is" without
6 //  express or implied warranty, and with no claim as to its suitability for
7 //  any purpose.
8
9 //  See http://www.boost.org for most recent version including documentation.
10
11 //  Revision History
12 //   31 Oct 01  use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
13 //   16 Apr 01  check LONGLONG_MAX when looking for "long long" (Jens Maurer)
14 //   23 Jan 01  prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
15 //   12 Nov 00  Merged <boost/stdint.h> (Jens Maurer)
16 //   23 Sep 00  Added INTXX_C macro support (John Maddock).
17 //   22 Sep 00  Better 64-bit support (John Maddock)
18 //   29 Jun 00  Reimplement to avoid including stdint.h within namespace boost
19 //    8 Aug 99  Initial version (Beman Dawes)
20
21
22 #ifndef BOOST_CSTDINT_HPP
23 #define BOOST_CSTDINT_HPP
24
25 #include <boost/config.hpp>
26
27
28 #ifdef BOOST_HAS_STDINT_H
29
30 // The following #include is an implementation artifact; not part of interface.
31 # ifdef __hpux
32 // HP-UX has a vaguely nice <stdint.h> in a non-standard location
33 #   include <inttypes.h>
34 #   ifdef __STDC_32_MODE__
35       // this is triggered with GCC, because it defines __cplusplus < 199707L
36 #     define BOOST_NO_INT64_T
37 #   endif 
38 # elif defined(__FreeBSD__)
39 #   include <inttypes.h>
40 # else
41 #   include <stdint.h>
42 # endif
43
44 namespace boost
45 {
46
47   using ::int8_t;             
48   using ::int_least8_t;       
49   using ::int_fast8_t;        
50   using ::uint8_t;            
51   using ::uint_least8_t;      
52   using ::uint_fast8_t;       
53                      
54   using ::int16_t;            
55   using ::int_least16_t;      
56   using ::int_fast16_t;       
57   using ::uint16_t;           
58   using ::uint_least16_t;     
59   using ::uint_fast16_t;      
60                      
61   using ::int32_t;            
62   using ::int_least32_t;      
63   using ::int_fast32_t;       
64   using ::uint32_t;           
65   using ::uint_least32_t;     
66   using ::uint_fast32_t;      
67                      
68 # ifndef BOOST_NO_INT64_T
69
70   using ::int64_t;            
71   using ::int_least64_t;      
72   using ::int_fast64_t;       
73   using ::uint64_t;           
74   using ::uint_least64_t;     
75   using ::uint_fast64_t;      
76                      
77 # endif
78
79   using ::intmax_t;      
80   using ::uintmax_t;     
81
82 } // namespace boost
83
84 #elif defined(__FreeBSD__) && (__FreeBSD__ <= 4)
85 // FreeBSD has an <inttypes.h> that contains much of what we need
86 # include <inttypes.h>
87
88 namespace boost {
89
90   using ::int8_t;             
91   typedef int8_t int_least8_t;       
92   typedef int8_t int_fast8_t;        
93   using ::uint8_t;            
94   typedef uint8_t uint_least8_t;      
95   typedef uint8_t uint_fast8_t;       
96                      
97   using ::int16_t;            
98   typedef int16_t int_least16_t;      
99   typedef int16_t int_fast16_t;       
100   using ::uint16_t;           
101   typedef uint16_t uint_least16_t;     
102   typedef uint16_t uint_fast16_t;      
103                      
104   using ::int32_t;            
105   typedef int32_t int_least32_t;      
106   typedef int32_t int_fast32_t;       
107   using ::uint32_t;           
108   typedef uint32_t uint_least32_t;     
109   typedef uint32_t uint_fast32_t;      
110          
111 # ifndef BOOST_NO_INT64_T          
112
113   using ::int64_t;            
114   typedef int64_t int_least64_t;      
115   typedef int64_t int_fast64_t;       
116   using ::uint64_t;           
117   typedef uint64_t uint_least64_t;     
118   typedef uint64_t uint_fast64_t;      
119
120   typedef int64_t intmax_t;
121   typedef uint64_t uintmax_t;
122
123 # else
124
125   typedef int32_t intmax_t;
126   typedef uint32_t uintmax_t;
127
128 # endif
129
130 } // namespace boost
131
132 #else  // BOOST_HAS_STDINT_H
133
134 # include <limits.h> // implementation artifact; not part of interface
135
136
137 namespace boost
138 {
139
140 //  These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
141 //  platforms.  For other systems, they will have to be hand tailored.
142 //
143 //  Because the fast types are assumed to be the same as the undecorated types,
144 //  it may be possible to hand tailor a more efficient implementation.  Such
145 //  an optimization may be illusionary; on the Intel x86-family 386 on, for
146 //  example, byte arithmetic and load/stores are as fast as "int" sized ones.
147
148 //  8-bit types  ------------------------------------------------------------//
149
150 # if UCHAR_MAX == 0xff
151      typedef signed char     int8_t;
152      typedef signed char     int_least8_t;
153      typedef signed char     int_fast8_t;
154      typedef unsigned char   uint8_t;
155      typedef unsigned char   uint_least8_t;
156      typedef unsigned char   uint_fast8_t;
157 # else
158 #    error defaults not correct; you must hand modify boost/cstdint.hpp
159 # endif
160
161 //  16-bit types  -----------------------------------------------------------//
162
163 # if USHRT_MAX == 0xffff
164      typedef short           int16_t;
165      typedef short           int_least16_t;
166      typedef short           int_fast16_t;
167      typedef unsigned short  uint16_t;
168      typedef unsigned short  uint_least16_t;
169      typedef unsigned short  uint_fast16_t;
170 # else
171 #    error defaults not correct; you must hand modify boost/cstdint.hpp
172 # endif
173
174 //  32-bit types  -----------------------------------------------------------//
175
176 # if ULONG_MAX == 0xffffffff
177      typedef long            int32_t;
178      typedef long            int_least32_t;
179      typedef long            int_fast32_t;
180      typedef unsigned long   uint32_t;
181      typedef unsigned long   uint_least32_t;
182      typedef unsigned long   uint_fast32_t;
183 # elif UINT_MAX == 0xffffffff
184      typedef int             int32_t;
185      typedef int             int_least32_t;
186      typedef int             int_fast32_t;
187      typedef unsigned int    uint32_t;
188      typedef unsigned int    uint_least32_t;
189      typedef unsigned int    uint_fast32_t;
190 # else
191 #    error defaults not correct; you must hand modify boost/cstdint.hpp
192 # endif
193
194 //  64-bit types + intmax_t and uintmax_t  ----------------------------------//
195
196 # if defined(BOOST_HAS_LONG_LONG) && \
197    !defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
198    (!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
199    (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
200 #    if defined(__hpux)
201      // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
202 #    elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
203                                                                  // 2**64 - 1
204 #    else
205 #       error defaults not correct; you must hand modify boost/cstdint.hpp
206 #    endif
207
208      typedef long long            intmax_t;
209      typedef unsigned long long   uintmax_t;
210      typedef long long            int64_t;
211      typedef long long            int_least64_t;
212      typedef long long            int_fast64_t;
213      typedef unsigned long long   uint64_t;
214      typedef unsigned long long   uint_least64_t;
215      typedef unsigned long long   uint_fast64_t;
216
217 # elif ULONG_MAX != 0xffffffff
218
219 #    if ULONG_MAX == 18446744073709551615 // 2**64 - 1
220      typedef long                 intmax_t;
221      typedef unsigned long        uintmax_t;
222      typedef long                 int64_t;
223      typedef long                 int_least64_t;
224      typedef long                 int_fast64_t;
225      typedef unsigned long        uint64_t;
226      typedef unsigned long        uint_least64_t;
227      typedef unsigned long        uint_fast64_t;
228 #    else
229 #       error defaults not correct; you must hand modify boost/cstdint.hpp
230 #    endif
231 # elif defined(BOOST_HAS_MS_INT64)
232      //
233      // we have Borland/Intel/Microsoft __int64:
234      //
235      typedef __int64             intmax_t;
236      typedef unsigned __int64    uintmax_t;
237      typedef __int64             int64_t;
238      typedef __int64             int_least64_t;
239      typedef __int64             int_fast64_t;
240      typedef unsigned __int64    uint64_t;
241      typedef unsigned __int64    uint_least64_t;
242      typedef unsigned __int64    uint_fast64_t;
243 # else // assume no 64-bit integers
244 #  define BOOST_NO_INT64_T
245      typedef int32_t              intmax_t;
246      typedef uint32_t             uintmax_t;
247 # endif
248
249 } // namespace boost
250
251
252 #endif // BOOST_HAS_STDINT_H
253
254 #endif // BOOST_CSTDINT_HPP
255
256
257 /****************************************************
258
259 Macro definition section:
260
261 Define various INTXX_C macros only if
262 __STDC_CONSTANT_MACROS is defined.
263
264 Undefine the macros if __STDC_CONSTANT_MACROS is
265 not defined and the macros are (cf <cassert>).
266
267 Added 23rd September 2000 (John Maddock).
268 Modified 11th September 2001 to be excluded when
269 BOOST_HAS_STDINT_H is defined (John Maddock).
270
271 ******************************************************/
272
273 #if defined(__STDC_CONSTANT_MACROS) && !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(BOOST_HAS_STDINT_H)
274 # define BOOST__STDC_CONSTANT_MACROS_DEFINED
275 # if defined(BOOST_HAS_MS_INT64)
276 //
277 // Borland/Intel/Microsoft compilers have width specific suffixes:
278 //
279 #  define INT8_C(value)     value##i8
280 #  define INT16_C(value)    value##i16
281 #  define INT32_C(value)    value##i32
282 #  define INT64_C(value)    value##i64
283 #  ifdef __BORLANDC__
284     // Borland bug: appending ui8 makes the type a signed char
285 #   define UINT8_C(value)    static_cast<unsigned char>(value##u)
286 #  else
287 #   define UINT8_C(value)    value##ui8
288 #  endif
289 #  define UINT16_C(value)   value##ui16
290 #  define UINT32_C(value)   value##ui32
291 #  define UINT64_C(value)   value##ui64
292 #  define INTMAX_C(value)   value##i64
293 #  define UINTMAX_C(value)  value##ui64
294
295 # else
296 //  do it the old fashioned way:
297
298 //  8-bit types  ------------------------------------------------------------//
299
300 #  if UCHAR_MAX == 0xff
301 #   define INT8_C(value) static_cast<boost::int8_t>(value)
302 #   define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
303 #  endif
304
305 //  16-bit types  -----------------------------------------------------------//
306
307 #  if USHRT_MAX == 0xffff
308 #   define INT16_C(value) static_cast<boost::int16_t>(value)
309 #   define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
310 #  endif
311
312 //  32-bit types  -----------------------------------------------------------//
313
314 #  if UINT_MAX == 0xffffffff
315 #   define INT32_C(value) value
316 #   define UINT32_C(value) value##u
317 #  elif ULONG_MAX == 0xffffffff
318 #   define INT32_C(value) value##L
319 #   define UINT32_C(value) value##uL
320 #  endif
321
322 //  64-bit types + intmax_t and uintmax_t  ----------------------------------//
323
324 #  if defined(BOOST_HAS_LONG_LONG) && \
325     (defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
326
327 #    if defined(__hpux)
328      // HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
329 #    elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615U) ||  \
330         (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615U) ||  \
331         (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615U)
332
333 #    else
334 #       error defaults not correct; you must hand modify boost/cstdint.hpp
335 #    endif
336 #    define INT64_C(value) value##LL
337 #    define UINT64_C(value) value##uLL
338 #  elif ULONG_MAX != 0xffffffff
339
340 #    if ULONG_MAX == 18446744073709551615 // 2**64 - 1
341 #       define INT64_C(value) value##L
342 #       define UINT64_C(value) value##uL
343 #    else
344 #       error defaults not correct; you must hand modify boost/cstdint.hpp
345 #    endif
346 #  endif
347
348 #  ifdef BOOST_NO_INT64_T
349 #   define INTMAX_C(value) INT32_C(value)
350 #   define UINTMAX_C(value) UINT32_C(value)
351 #  else
352 #   define INTMAX_C(value) INT64_C(value)
353 #   define UINTMAX_C(value) UINT64_C(value)
354 #  endif
355
356 # endif // Borland/Microsoft specific width suffixes
357
358
359 #elif defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && !defined(__STDC_CONSTANT_MACROS) && !defined(BOOST_HAS_STDINT_H)
360 //
361 // undef all the macros:
362 //
363 # undef INT8_C
364 # undef INT16_C
365 # undef INT32_C
366 # undef INT64_C
367 # undef UINT8_C
368 # undef UINT16_C
369 # undef UINT32_C
370 # undef UINT64_C
371 # undef INTMAX_C
372 # undef UINTMAX_C
373
374 #endif // __STDC_CONSTANT_MACROS_DEFINED etc.
375
376