usermode/library/common/cuckoo_hash/PortableStdint.h

00001 /*  A portable stdint.h
00002  ****************************************************************************
00003  *  BSD License:
00004  ****************************************************************************
00005  *
00006  *  Copyright (c) 2005-2007 Paul Hsieh
00007  *  All rights reserved.
00008  *  
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *  
00013  *  1. Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *  2. Redistributions in binary form must reproduce the above copyright
00016  *     notice, this list of conditions and the following disclaimer in the
00017  *     documentation and/or other materials provided with the distribution.
00018  *  3. The name of the author may not be used to endorse or promote products
00019  *     derived from this software without specific prior written permission.
00020  *  
00021  *  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00022  *  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023  *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00024  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00026  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00030  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  ****************************************************************************
00033  *
00034  *  Version 0.1.11
00035  *
00036  *  The ANSI C standard committee, for the C99 standard, specified the
00037  *  inclusion of a new standard include file called stdint.h.  This is
00038  *  a very useful and long desired include file which contains several
00039  *  very precise definitions for integer scalar types that is
00040  *  critically important for making portable several classes of
00041  *  applications including cryptography, hashing, variable length
00042  *  integer libraries and so on.  But for most developers its likely
00043  *  useful just for programming sanity.
00044  *
00045  *  The problem is that most compiler vendors have decided not to
00046  *  implement the C99 standard, and the next C++ language standard
00047  *  (which has a lot more mindshare these days) will be a long time in
00048  *  coming and its unknown whether or not it will include stdint.h or
00049  *  how much adoption it will have.  Either way, it will be a long time
00050  *  before all compilers come with a stdint.h and it also does nothing
00051  *  for the extremely large number of compilers available today which
00052  *  do not include this file, or anything comparable to it.
00053  *
00054  *  So that's what this file is all about.  Its an attempt to build a
00055  *  single universal include file that works on as many platforms as
00056  *  possible to deliver what stdint.h is supposed to.  A few things
00057  *  that should be noted about this file:
00058  *
00059  *    1) It is not guaranteed to be portable and/or present an identical
00060  *       interface on all platforms.  The extreme variability of the
00061  *       ANSI C standard makes this an impossibility right from the
00062  *       very get go. Its really only meant to be useful for the vast
00063  *       majority of platforms that possess the capability of
00064  *       implementing usefully and precisely defined, standard sized
00065  *       integer scalars.  Systems which are not intrinsically 2s
00066  *       complement may produce invalid constants.
00067  *
00068  *    2) There is an unavoidable use of non-reserved symbols.
00069  *
00070  *    3) Other standard include files are invoked.
00071  *
00072  *    4) This file may come in conflict with future platforms that do
00073  *       include stdint.h.  The hope is that one or the other can be
00074  *       used with no real difference.
00075  *
00076  *    5) In the current verison, if your platform can't represent
00077  *       int32_t, int16_t and int8_t, it just dumps out with a compiler
00078  *       error.
00079  *
00080  *    6) 64 bit integers may or may not be defined.  Test for their
00081  *       presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX.
00082  *       Note that this is different from the C99 specification which
00083  *       requires the existence of 64 bit support in the compiler.  If
00084  *       this is not defined for your platform, yet it is capable of
00085  *       dealing with 64 bits then it is because this file has not yet
00086  *       been extended to cover all of your system's capabilities.
00087  *
00088  *    7) (u)intptr_t may or may not be defined.  Test for its presence
00089  *       with the test: #ifdef PTRDIFF_MAX.  If this is not defined
00090  *       for your platform, then it is because this file has not yet
00091  *       been extended to cover all of your system's capabilities, not
00092  *       because its optional.
00093  *
00094  *    8) The following might not been defined even if your platform is
00095  *       capable of defining it:
00096  *
00097  *       WCHAR_MIN
00098  *       WCHAR_MAX
00099  *       (u)int64_t
00100  *       PTRDIFF_MIN
00101  *       PTRDIFF_MAX
00102  *       (u)intptr_t
00103  *
00104  *    9) The following have not been defined:
00105  *
00106  *       WINT_MIN
00107  *       WINT_MAX
00108  *
00109  *   10) The criteria for defining (u)int_least(*)_t isn't clear,
00110  *       except for systems which don't have a type that precisely
00111  *       defined 8, 16, or 32 bit types (which this include file does
00112  *       not support anyways). Default definitions have been given.
00113  *
00114  *   11) The criteria for defining (u)int_fast(*)_t isn't something I
00115  *       would trust to any particular compiler vendor or the ANSI C
00116  *       committee.  It is well known that "compatible systems" are
00117  *       commonly created that have very different performance
00118  *       characteristics from the systems they are compatible with,
00119  *       especially those whose vendors make both the compiler and the
00120  *       system.  Default definitions have been given, but its strongly
00121  *       recommended that users never use these definitions for any
00122  *       reason (they do *NOT* deliver any serious guarantee of
00123  *       improved performance -- not in this file, nor any vendor's
00124  *       stdint.h).
00125  *
00126  *   12) The following macros:
00127  *
00128  *       PRINTF_INTMAX_MODIFIER
00129  *       PRINTF_INT64_MODIFIER
00130  *       PRINTF_INT32_MODIFIER
00131  *       PRINTF_INT16_MODIFIER
00132  *       PRINTF_LEAST64_MODIFIER
00133  *       PRINTF_LEAST32_MODIFIER
00134  *       PRINTF_LEAST16_MODIFIER
00135  *       PRINTF_INTPTR_MODIFIER
00136  *
00137  *       are strings which have been defined as the modifiers required
00138  *       for the "d", "u" and "x" printf formats to correctly output
00139  *       (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t,
00140  *       (u)least32_t, (u)least16_t and (u)intptr_t types respectively.
00141  *       PRINTF_INTPTR_MODIFIER is not defined for some systems which
00142  *       provide their own stdint.h.  PRINTF_INT64_MODIFIER is not
00143  *       defined if INT64_MAX is not defined.  These are an extension
00144  *       beyond what C99 specifies must be in stdint.h.
00145  *
00146  *       In addition, the following macros are defined:
00147  *
00148  *       PRINTF_INTMAX_HEX_WIDTH
00149  *       PRINTF_INT64_HEX_WIDTH
00150  *       PRINTF_INT32_HEX_WIDTH
00151  *       PRINTF_INT16_HEX_WIDTH
00152  *       PRINTF_INT8_HEX_WIDTH
00153  *       PRINTF_INTMAX_DEC_WIDTH
00154  *       PRINTF_INT64_DEC_WIDTH
00155  *       PRINTF_INT32_DEC_WIDTH
00156  *       PRINTF_INT16_DEC_WIDTH
00157  *       PRINTF_INT8_DEC_WIDTH
00158  *
00159  *       Which specifies the maximum number of characters required to
00160  *       print the number of that type in either hexadecimal or decimal.
00161  *       These are an extension beyond what C99 specifies must be in
00162  *       stdint.h.
00163  *
00164  *  Compilers tested (all with 0 warnings at their highest respective
00165  *  settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32
00166  *  bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio
00167  *  .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3
00168  *
00169  *  This file should be considered a work in progress.  Suggestions for
00170  *  improvements, especially those which increase coverage are strongly
00171  *  encouraged.
00172  *
00173  *  Acknowledgements
00174  *
00175  *  The following people have made significant contributions to the
00176  *  development and testing of this file:
00177  *
00178  *  Chris Howie
00179  *  John Steele Scott
00180  *  Dave Thorup
00181  *
00182  */
00183 
00184 #include <stddef.h>
00185 #include <limits.h>
00186 #include <signal.h>
00187 
00188 /*
00189  *  For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and
00190  *  do nothing else.  On the Mac OS X version of gcc this is _STDINT_H_.
00191  */
00192 
00193 #if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined (__WATCOMC__) && (defined (_STDINT_H_INCLUDED) || __WATCOMC__ >= 1250)) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) )) && !defined (_PSTDINT_H_INCLUDED) || defined(__FreeBSD__)
00194 #include <stdint.h>
00195 #define _PSTDINT_H_INCLUDED
00196 # ifndef PRINTF_INT64_MODIFIER
00197 #  define PRINTF_INT64_MODIFIER "ll"
00198 # endif
00199 # ifndef PRINTF_INT32_MODIFIER
00200 #  define PRINTF_INT32_MODIFIER "l"
00201 # endif
00202 # ifndef PRINTF_INT16_MODIFIER
00203 #  define PRINTF_INT16_MODIFIER "h"
00204 # endif
00205 # ifndef PRINTF_INTMAX_MODIFIER
00206 #  define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
00207 # endif
00208 # ifndef PRINTF_INT64_HEX_WIDTH
00209 #  define PRINTF_INT64_HEX_WIDTH "16"
00210 # endif
00211 # ifndef PRINTF_INT32_HEX_WIDTH
00212 #  define PRINTF_INT32_HEX_WIDTH "8"
00213 # endif
00214 # ifndef PRINTF_INT16_HEX_WIDTH
00215 #  define PRINTF_INT16_HEX_WIDTH "4"
00216 # endif
00217 # ifndef PRINTF_INT8_HEX_WIDTH
00218 #  define PRINTF_INT8_HEX_WIDTH "2"
00219 # endif
00220 # ifndef PRINTF_INT64_DEC_WIDTH
00221 #  define PRINTF_INT64_DEC_WIDTH "20"
00222 # endif
00223 # ifndef PRINTF_INT32_DEC_WIDTH
00224 #  define PRINTF_INT32_DEC_WIDTH "10"
00225 # endif
00226 # ifndef PRINTF_INT16_DEC_WIDTH
00227 #  define PRINTF_INT16_DEC_WIDTH "5"
00228 # endif
00229 # ifndef PRINTF_INT8_DEC_WIDTH
00230 #  define PRINTF_INT8_DEC_WIDTH "3"
00231 # endif
00232 # ifndef PRINTF_INTMAX_HEX_WIDTH
00233 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
00234 # endif
00235 # ifndef PRINTF_INTMAX_DEC_WIDTH
00236 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
00237 # endif
00238 
00239 /*
00240  *  Something really weird is going on with Open Watcom.  Just pull some of
00241  *  these duplicated definitions from Open Watcom's stdint.h file for now.
00242  */
00243 
00244 # if defined (__WATCOMC__) && __WATCOMC__ >= 1250
00245 #  if !defined (INT64_C)
00246 #   define INT64_C(x)   (x + (INT64_MAX - INT64_MAX))
00247 #  endif
00248 #  if !defined (UINT64_C)
00249 #   define UINT64_C(x)  (x + (UINT64_MAX - UINT64_MAX))
00250 #  endif
00251 #  if !defined (INT32_C)
00252 #   define INT32_C(x)   (x + (INT32_MAX - INT32_MAX))
00253 #  endif
00254 #  if !defined (UINT32_C)
00255 #   define UINT32_C(x)  (x + (UINT32_MAX - UINT32_MAX))
00256 #  endif
00257 #  if !defined (INT16_C)
00258 #   define INT16_C(x)   (x)
00259 #  endif
00260 #  if !defined (UINT16_C)
00261 #   define UINT16_C(x)  (x)
00262 #  endif
00263 #  if !defined (INT8_C)
00264 #   define INT8_C(x)   (x)
00265 #  endif
00266 #  if !defined (UINT8_C)
00267 #   define UINT8_C(x)  (x)
00268 #  endif
00269 #  if !defined (UINT64_MAX)
00270 #   define UINT64_MAX  18446744073709551615ULL
00271 #  endif
00272 #  if !defined (INT64_MAX)
00273 #   define INT64_MAX  9223372036854775807LL
00274 #  endif
00275 #  if !defined (UINT32_MAX)
00276 #   define UINT32_MAX  4294967295UL
00277 #  endif
00278 #  if !defined (INT32_MAX)
00279 #   define INT32_MAX  2147483647L
00280 #  endif
00281 #  if !defined (INTMAX_MAX)
00282 #   define INTMAX_MAX INT64_MAX
00283 #  endif
00284 #  if !defined (INTMAX_MIN)
00285 #   define INTMAX_MIN INT64_MIN
00286 #  endif
00287 # endif
00288 #endif
00289 
00290 #ifndef _PSTDINT_H_INCLUDED
00291 #define _PSTDINT_H_INCLUDED
00292 
00293 #ifndef SIZE_MAX
00294 # define SIZE_MAX (~(size_t)0)
00295 #endif
00296 
00297 /*
00298  *  Deduce the type assignments from limits.h under the assumption that
00299  *  integer sizes in bits are powers of 2, and follow the ANSI
00300  *  definitions.
00301  */
00302 
00303 #ifndef UINT8_MAX
00304 # define UINT8_MAX 0xff
00305 #endif
00306 #ifndef uint8_t
00307 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S)
00308     typedef unsigned char uint8_t;
00309 #   define UINT8_C(v) ((uint8_t) v)
00310 # else
00311 #   error "Platform not supported"
00312 # endif
00313 #endif
00314 
00315 #ifndef INT8_MAX
00316 # define INT8_MAX 0x7f
00317 #endif
00318 #ifndef INT8_MIN
00319 # define INT8_MIN INT8_C(0x80)
00320 #endif
00321 #ifndef int8_t
00322 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S)
00323     typedef signed char int8_t;
00324 #   define INT8_C(v) ((int8_t) v)
00325 # else
00326 #   error "Platform not supported"
00327 # endif
00328 #endif
00329 
00330 #ifndef UINT16_MAX
00331 # define UINT16_MAX 0xffff
00332 #endif
00333 #ifndef uint16_t
00334 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S)
00335   typedef unsigned int uint16_t;
00336 # ifndef PRINTF_INT16_MODIFIER
00337 #  define PRINTF_INT16_MODIFIER ""
00338 # endif
00339 # define UINT16_C(v) ((uint16_t) (v))
00340 #elif (USHRT_MAX == UINT16_MAX)
00341   typedef unsigned short uint16_t;
00342 # define UINT16_C(v) ((uint16_t) (v))
00343 # ifndef PRINTF_INT16_MODIFIER
00344 #  define PRINTF_INT16_MODIFIER "h"
00345 # endif
00346 #else
00347 #error "Platform not supported"
00348 #endif
00349 #endif
00350 
00351 #ifndef INT16_MAX
00352 # define INT16_MAX 0x7fff
00353 #endif
00354 #ifndef INT16_MIN
00355 # define INT16_MIN INT16_C(0x8000)
00356 #endif
00357 #ifndef int16_t
00358 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S)
00359   typedef signed int int16_t;
00360 # define INT16_C(v) ((int16_t) (v))
00361 # ifndef PRINTF_INT16_MODIFIER
00362 #  define PRINTF_INT16_MODIFIER ""
00363 # endif
00364 #elif (SHRT_MAX == INT16_MAX)
00365   typedef signed short int16_t;
00366 # define INT16_C(v) ((int16_t) (v))
00367 # ifndef PRINTF_INT16_MODIFIER
00368 #  define PRINTF_INT16_MODIFIER "h"
00369 # endif
00370 #else
00371 #error "Platform not supported"
00372 #endif
00373 #endif
00374 
00375 #ifndef UINT32_MAX
00376 # define UINT32_MAX (0xffffffffUL)
00377 #endif
00378 #ifndef uint32_t
00379 #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S)
00380   typedef unsigned long uint32_t;
00381 # define UINT32_C(v) v ## UL
00382 # ifndef PRINTF_INT32_MODIFIER
00383 #  define PRINTF_INT32_MODIFIER "l"
00384 # endif
00385 #elif (UINT_MAX == UINT32_MAX)
00386   typedef unsigned int uint32_t;
00387 # ifndef PRINTF_INT32_MODIFIER
00388 #  define PRINTF_INT32_MODIFIER ""
00389 # endif
00390 # define UINT32_C(v) v ## U
00391 #elif (USHRT_MAX == UINT32_MAX)
00392   typedef unsigned short uint32_t;
00393 # define UINT32_C(v) ((unsigned short) (v))
00394 # ifndef PRINTF_INT32_MODIFIER
00395 #  define PRINTF_INT32_MODIFIER ""
00396 # endif
00397 #else
00398 #error "Platform not supported"
00399 #endif
00400 #endif
00401 
00402 #ifndef INT32_MAX
00403 # define INT32_MAX (0x7fffffffL)
00404 #endif
00405 #ifndef INT32_MIN
00406 # define INT32_MIN INT32_C(0x80000000)
00407 #endif
00408 #ifndef int32_t
00409 #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S)
00410   typedef signed long int32_t;
00411 # define INT32_C(v) v ## L
00412 # ifndef PRINTF_INT32_MODIFIER
00413 #  define PRINTF_INT32_MODIFIER "l"
00414 # endif
00415 #elif (INT_MAX == INT32_MAX)
00416   typedef signed int int32_t;
00417 # define INT32_C(v) v
00418 # ifndef PRINTF_INT32_MODIFIER
00419 #  define PRINTF_INT32_MODIFIER ""
00420 # endif
00421 #elif (SHRT_MAX == INT32_MAX)
00422   typedef signed short int32_t;
00423 # define INT32_C(v) ((short) (v))
00424 # ifndef PRINTF_INT32_MODIFIER
00425 #  define PRINTF_INT32_MODIFIER ""
00426 # endif
00427 #else
00428 #error "Platform not supported"
00429 #endif
00430 #endif
00431 
00432 /*
00433  *  The macro stdint_int64_defined is temporarily used to record
00434  *  whether or not 64 integer support is available.  It must be
00435  *  defined for any 64 integer extensions for new platforms that are
00436  *  added.
00437  */
00438 
00439 #undef stdint_int64_defined
00440 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S)
00441 # if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S)
00442 #  define stdint_int64_defined
00443    typedef long long int64_t;
00444    typedef unsigned long long uint64_t;
00445 #  define UINT64_C(v) v ## ULL
00446 #  define  INT64_C(v) v ## LL
00447 #  ifndef PRINTF_INT64_MODIFIER
00448 #   define PRINTF_INT64_MODIFIER "ll"
00449 #  endif
00450 # endif
00451 #endif
00452 
00453 #if !defined (stdint_int64_defined)
00454 # if defined(__GNUC__)
00455 #  define stdint_int64_defined
00456    __extension__ typedef long long int64_t;
00457    __extension__ typedef unsigned long long uint64_t;
00458 #  define UINT64_C(v) v ## ULL
00459 #  define  INT64_C(v) v ## LL
00460 #  ifndef PRINTF_INT64_MODIFIER
00461 #   define PRINTF_INT64_MODIFIER "ll"
00462 #  endif
00463 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S)
00464 #  define stdint_int64_defined
00465    typedef long long int64_t;
00466    typedef unsigned long long uint64_t;
00467 #  define UINT64_C(v) v ## ULL
00468 #  define  INT64_C(v) v ## LL
00469 #  ifndef PRINTF_INT64_MODIFIER
00470 #   define PRINTF_INT64_MODIFIER "ll"
00471 #  endif
00472 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC)
00473 #  define stdint_int64_defined
00474    typedef __int64 int64_t;
00475    typedef unsigned __int64 uint64_t;
00476 #  define UINT64_C(v) v ## UI64
00477 #  define  INT64_C(v) v ## I64
00478 #  ifndef PRINTF_INT64_MODIFIER
00479 #   define PRINTF_INT64_MODIFIER "I64"
00480 #  endif
00481 # endif
00482 #endif
00483 
00484 #if !defined (LONG_LONG_MAX) && defined (INT64_C)
00485 # define LONG_LONG_MAX INT64_C (9223372036854775807)
00486 #endif
00487 #ifndef ULONG_LONG_MAX
00488 # define ULONG_LONG_MAX UINT64_C (18446744073709551615)
00489 #endif
00490 
00491 #if !defined (INT64_MAX) && defined (INT64_C)
00492 # define INT64_MAX INT64_C (9223372036854775807)
00493 #endif
00494 #if !defined (INT64_MIN) && defined (INT64_C)
00495 # define INT64_MIN INT64_C (-9223372036854775808)
00496 #endif
00497 #if !defined (UINT64_MAX) && defined (INT64_C)
00498 # define UINT64_MAX UINT64_C (18446744073709551615)
00499 #endif
00500 
00501 /*
00502  *  Width of hexadecimal for number field.
00503  */
00504 
00505 #ifndef PRINTF_INT64_HEX_WIDTH
00506 # define PRINTF_INT64_HEX_WIDTH "16"
00507 #endif
00508 #ifndef PRINTF_INT32_HEX_WIDTH
00509 # define PRINTF_INT32_HEX_WIDTH "8"
00510 #endif
00511 #ifndef PRINTF_INT16_HEX_WIDTH
00512 # define PRINTF_INT16_HEX_WIDTH "4"
00513 #endif
00514 #ifndef PRINTF_INT8_HEX_WIDTH
00515 # define PRINTF_INT8_HEX_WIDTH "2"
00516 #endif
00517 
00518 #ifndef PRINTF_INT64_DEC_WIDTH
00519 # define PRINTF_INT64_DEC_WIDTH "20"
00520 #endif
00521 #ifndef PRINTF_INT32_DEC_WIDTH
00522 # define PRINTF_INT32_DEC_WIDTH "10"
00523 #endif
00524 #ifndef PRINTF_INT16_DEC_WIDTH
00525 # define PRINTF_INT16_DEC_WIDTH "5"
00526 #endif
00527 #ifndef PRINTF_INT8_DEC_WIDTH
00528 # define PRINTF_INT8_DEC_WIDTH "3"
00529 #endif
00530 
00531 /*
00532  *  Ok, lets not worry about 128 bit integers for now.  Moore's law says
00533  *  we don't need to worry about that until about 2040 at which point
00534  *  we'll have bigger things to worry about.
00535  */
00536 
00537 #ifdef stdint_int64_defined
00538   typedef int64_t intmax_t;
00539   typedef uint64_t uintmax_t;
00540 # define  INTMAX_MAX   INT64_MAX
00541 # define  INTMAX_MIN   INT64_MIN
00542 # define UINTMAX_MAX  UINT64_MAX
00543 # define UINTMAX_C(v) UINT64_C(v)
00544 # define  INTMAX_C(v)  INT64_C(v)
00545 # ifndef PRINTF_INTMAX_MODIFIER
00546 #   define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER
00547 # endif
00548 # ifndef PRINTF_INTMAX_HEX_WIDTH
00549 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH
00550 # endif
00551 # ifndef PRINTF_INTMAX_DEC_WIDTH
00552 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH
00553 # endif
00554 #else
00555   typedef int32_t intmax_t;
00556   typedef uint32_t uintmax_t;
00557 # define  INTMAX_MAX   INT32_MAX
00558 # define UINTMAX_MAX  UINT32_MAX
00559 # define UINTMAX_C(v) UINT32_C(v)
00560 # define  INTMAX_C(v)  INT32_C(v)
00561 # ifndef PRINTF_INTMAX_MODIFIER
00562 #   define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER
00563 # endif
00564 # ifndef PRINTF_INTMAX_HEX_WIDTH
00565 #  define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH
00566 # endif
00567 # ifndef PRINTF_INTMAX_DEC_WIDTH
00568 #  define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH
00569 # endif
00570 #endif
00571 
00572 /*
00573  *  Because this file currently only supports platforms which have
00574  *  precise powers of 2 as bit sizes for the default integers, the
00575  *  least definitions are all trivial.  Its possible that a future
00576  *  version of this file could have different definitions.
00577  */
00578 
00579 #ifndef stdint_least_defined
00580   typedef   int8_t   int_least8_t;
00581   typedef  uint8_t  uint_least8_t;
00582   typedef  int16_t  int_least16_t;
00583   typedef uint16_t uint_least16_t;
00584   typedef  int32_t  int_least32_t;
00585   typedef uint32_t uint_least32_t;
00586 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER
00587 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER
00588 # define  UINT_LEAST8_MAX  UINT8_MAX
00589 # define   INT_LEAST8_MAX   INT8_MAX
00590 # define UINT_LEAST16_MAX UINT16_MAX
00591 # define  INT_LEAST16_MAX  INT16_MAX
00592 # define UINT_LEAST32_MAX UINT32_MAX
00593 # define  INT_LEAST32_MAX  INT32_MAX
00594 # define   INT_LEAST8_MIN   INT8_MIN
00595 # define  INT_LEAST16_MIN  INT16_MIN
00596 # define  INT_LEAST32_MIN  INT32_MIN
00597 # ifdef stdint_int64_defined
00598     typedef  int64_t  int_least64_t;
00599     typedef uint64_t uint_least64_t;
00600 #   define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER
00601 #   define UINT_LEAST64_MAX UINT64_MAX
00602 #   define  INT_LEAST64_MAX  INT64_MAX
00603 #   define  INT_LEAST64_MIN  INT64_MIN
00604 # endif
00605 #endif
00606 #undef stdint_least_defined
00607 
00608 /*
00609  *  The ANSI C committee pretending to know or specify anything about
00610  *  performance is the epitome of misguided arrogance.  The mandate of
00611  *  this file is to *ONLY* ever support that absolute minimum
00612  *  definition of the fast integer types, for compatibility purposes.
00613  *  No extensions, and no attempt to suggest what may or may not be a
00614  *  faster integer type will ever be made in this file.  Developers are
00615  *  warned to stay away from these types when using this or any other
00616  *  stdint.h.
00617  */
00618 
00619 typedef   int_least8_t   int_fast8_t;
00620 typedef  uint_least8_t  uint_fast8_t;
00621 typedef  int_least16_t  int_fast16_t;
00622 typedef uint_least16_t uint_fast16_t;
00623 typedef  int_least32_t  int_fast32_t;
00624 typedef uint_least32_t uint_fast32_t;
00625 #define  UINT_FAST8_MAX  UINT_LEAST8_MAX
00626 #define   INT_FAST8_MAX   INT_LEAST8_MAX
00627 #define UINT_FAST16_MAX UINT_LEAST16_MAX
00628 #define  INT_FAST16_MAX  INT_LEAST16_MAX
00629 #define UINT_FAST32_MAX UINT_LEAST32_MAX
00630 #define  INT_FAST32_MAX  INT_LEAST32_MAX
00631 #define   INT_FAST8_MIN   INT_LEAST8_MIN
00632 #define  INT_FAST16_MIN  INT_LEAST16_MIN
00633 #define  INT_FAST32_MIN  INT_LEAST32_MIN
00634 #ifdef stdint_int64_defined
00635   typedef  int_least64_t  int_fast64_t;
00636   typedef uint_least64_t uint_fast64_t;
00637 # define UINT_FAST64_MAX UINT_LEAST64_MAX
00638 # define  INT_FAST64_MAX  INT_LEAST64_MAX
00639 # define  INT_FAST64_MIN  INT_LEAST64_MIN
00640 #endif
00641 
00642 #undef stdint_int64_defined
00643 
00644 /*
00645  *  Whatever piecemeal, per compiler thing we can do about the wchar_t
00646  *  type limits.
00647  */
00648 
00649 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__)
00650 # include <wchar.h>
00651 # ifndef WCHAR_MIN
00652 #  define WCHAR_MIN 0
00653 # endif
00654 # ifndef WCHAR_MAX
00655 #  define WCHAR_MAX ((wchar_t)-1)
00656 # endif
00657 #endif
00658 
00659 /*
00660  *  Whatever piecemeal, per compiler/platform thing we can do about the
00661  *  (u)intptr_t types and limits.
00662  */
00663 
00664 #if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED)
00665 # define STDINT_H_UINTPTR_T_DEFINED
00666 #endif
00667 
00668 #ifndef STDINT_H_UINTPTR_T_DEFINED
00669 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64)
00670 #  define stdint_intptr_bits 64
00671 # elif defined (__WATCOMC__) || defined (__TURBOC__)
00672 #  if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
00673 #    define stdint_intptr_bits 16
00674 #  else
00675 #    define stdint_intptr_bits 32
00676 #  endif
00677 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32)
00678 #  define stdint_intptr_bits 32
00679 # elif defined (__INTEL_COMPILER)
00680 /* TODO -- what will Intel do about x86-64? */
00681 # endif
00682 
00683 # ifdef stdint_intptr_bits
00684 #  define stdint_intptr_glue3_i(a,b,c)  a##b##c
00685 #  define stdint_intptr_glue3(a,b,c)    stdint_intptr_glue3_i(a,b,c)
00686 #  ifndef PRINTF_INTPTR_MODIFIER
00687 #    define PRINTF_INTPTR_MODIFIER      stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER)
00688 #  endif
00689 #  ifndef PTRDIFF_MAX
00690 #    define PTRDIFF_MAX                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
00691 #  endif
00692 #  ifndef PTRDIFF_MIN
00693 #    define PTRDIFF_MIN                 stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
00694 #  endif
00695 #  ifndef UINTPTR_MAX
00696 #    define UINTPTR_MAX                 stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX)
00697 #  endif
00698 #  ifndef INTPTR_MAX
00699 #    define INTPTR_MAX                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX)
00700 #  endif
00701 #  ifndef INTPTR_MIN
00702 #    define INTPTR_MIN                  stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN)
00703 #  endif
00704 #  ifndef INTPTR_C
00705 #    define INTPTR_C(x)                 stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x)
00706 #  endif
00707 #  ifndef UINTPTR_C
00708 #    define UINTPTR_C(x)                stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x)
00709 #  endif
00710   typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t;
00711   typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t)  intptr_t;
00712 # else
00713 /* TODO -- This following is likely wrong for some platforms, and does
00714    nothing for the definition of uintptr_t. */
00715   typedef ptrdiff_t intptr_t;
00716 # endif
00717 # define STDINT_H_UINTPTR_T_DEFINED
00718 #endif
00719 
00720 /*
00721  *  Assumes sig_atomic_t is signed and we have a 2s complement machine.
00722  */
00723 
00724 #ifndef SIG_ATOMIC_MAX
00725 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1)
00726 #endif
00727 
00728 #endif
00729 
00730 #if defined (__TEST_PSTDINT_FOR_CORRECTNESS)
00731 
00732 /* 
00733  *  Please compile with the maximum warning settings to make sure macros are not
00734  *  defined more than once.
00735  */
00736  
00737 #include <stdlib.h>
00738 #include <stdio.h>
00739 #include <string.h>
00740  
00741 #define glue3_aux(x,y,z) x ## y ## z
00742 #define glue3(x,y,z) glue3_aux(x,y,z)
00743 
00744 #define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0);
00745 #define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0);
00746 
00747 #define DECL(us,bits) glue3(DECL,us,) (bits)
00748 
00749 #define TESTUMAX(bits) glue3(u,bits,=) glue3(~,u,bits); if (glue3(UINT,bits,_MAX) glue3(!=,u,bits)) printf ("Something wrong with UINT%d_MAX\n", bits)
00750  
00751 int main () {
00752         DECL(I,8)
00753         DECL(U,8)
00754         DECL(I,16)
00755         DECL(U,16)
00756         DECL(I,32)
00757         DECL(U,32)
00758 #ifdef INT64_MAX
00759         DECL(I,64)
00760         DECL(U,64)
00761 #endif
00762         intmax_t imax = INTMAX_C(0);
00763         uintmax_t umax = UINTMAX_C(0);
00764         char str0[256], str1[256];
00765 
00766         sprintf (str0, "%d %x\n", 0, ~0);
00767         
00768         sprintf (str1, "%d %x\n",  i8, ~0);
00769         if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1);
00770         sprintf (str1, "%u %x\n",  u8, ~0);
00771         if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1);
00772         sprintf (str1, "%d %x\n",  i16, ~0);
00773         if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1);
00774         sprintf (str1, "%u %x\n",  u16, ~0);
00775         if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1); 
00776         sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n",  i32, ~0);
00777         if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1);
00778         sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n",  u32, ~0);
00779         if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1);
00780 #ifdef INT64_MAX        
00781         sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n",  i64, ~0);
00782         if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1);
00783 #endif
00784         sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n",  imax, ~0);
00785         if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1);
00786         sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n",  umax, ~0);
00787         if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1);        
00788         
00789         TESTUMAX(8);
00790         TESTUMAX(16);
00791         TESTUMAX(32);
00792 #ifdef INT64_MAX
00793         TESTUMAX(64);
00794 #endif
00795 
00796         return EXIT_SUCCESS;
00797 }
00798 
00799 #endif

Generated on Sat Apr 23 11:43:35 2011 for Mnemosyne by  doxygen 1.4.7