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__) && __WATCOMC__ >= 1250) || (defined(__GNUC__) && __GNUC__ > 2) 00194 #include <stdint.h> 00195 #endif 00196 00197 #if (defined (_STDINT_H_INCLUDED) || defined (_STDINT_H) || defined (_STDINT_H_)) && !defined (_PSTDINT_H_INCLUDED) 00198 #define _PSTDINT_H_INCLUDED 00199 # ifndef PRINTF_INT64_MODIFIER 00200 # if __WORDSIZE == 64 00201 # define PRINTF_INT64_MODIFIER "l" 00202 # else 00203 # define PRINTF_INT64_MODIFIER "ll" 00204 # endif 00205 # endif 00206 # ifndef PRINTF_INT32_MODIFIER 00207 # if (LONG_MAX == INT32_MAX) 00208 # define PRINTF_INT32_MODIFIER "l" 00209 # else 00210 # define PRINTF_INT32_MODIFIER "" 00211 # endif 00212 # endif 00213 # ifndef PRINTF_INT16_MODIFIER 00214 # define PRINTF_INT16_MODIFIER "h" 00215 # endif 00216 # ifndef PRINTF_INTMAX_MODIFIER 00217 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER 00218 # endif 00219 # ifndef PRINTF_INT64_HEX_WIDTH 00220 # define PRINTF_INT64_HEX_WIDTH "16" 00221 # endif 00222 # ifndef PRINTF_INT32_HEX_WIDTH 00223 # define PRINTF_INT32_HEX_WIDTH "8" 00224 # endif 00225 # ifndef PRINTF_INT16_HEX_WIDTH 00226 # define PRINTF_INT16_HEX_WIDTH "4" 00227 # endif 00228 # ifndef PRINTF_INT8_HEX_WIDTH 00229 # define PRINTF_INT8_HEX_WIDTH "2" 00230 # endif 00231 # ifndef PRINTF_INT64_DEC_WIDTH 00232 # define PRINTF_INT64_DEC_WIDTH "20" 00233 # endif 00234 # ifndef PRINTF_INT32_DEC_WIDTH 00235 # define PRINTF_INT32_DEC_WIDTH "10" 00236 # endif 00237 # ifndef PRINTF_INT16_DEC_WIDTH 00238 # define PRINTF_INT16_DEC_WIDTH "5" 00239 # endif 00240 # ifndef PRINTF_INT8_DEC_WIDTH 00241 # define PRINTF_INT8_DEC_WIDTH "3" 00242 # endif 00243 # ifndef PRINTF_INTMAX_HEX_WIDTH 00244 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH 00245 # endif 00246 # ifndef PRINTF_INTMAX_DEC_WIDTH 00247 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH 00248 # endif 00249 00250 /* 00251 * Something really weird is going on with Open Watcom. Just pull some of 00252 * these duplicated definitions from Open Watcom's stdint.h file for now. 00253 */ 00254 00255 # if defined (__WATCOMC__) && __WATCOMC__ >= 1250 00256 # if !defined (INT64_C) 00257 # define INT64_C(x) (x + (INT64_MAX - INT64_MAX)) 00258 # endif 00259 # if !defined (UINT64_C) 00260 # define UINT64_C(x) (x + (UINT64_MAX - UINT64_MAX)) 00261 # endif 00262 # if !defined (INT32_C) 00263 # define INT32_C(x) (x + (INT32_MAX - INT32_MAX)) 00264 # endif 00265 # if !defined (UINT32_C) 00266 # define UINT32_C(x) (x + (UINT32_MAX - UINT32_MAX)) 00267 # endif 00268 # if !defined (INT16_C) 00269 # define INT16_C(x) (x) 00270 # endif 00271 # if !defined (UINT16_C) 00272 # define UINT16_C(x) (x) 00273 # endif 00274 # if !defined (INT8_C) 00275 # define INT8_C(x) (x) 00276 # endif 00277 # if !defined (UINT8_C) 00278 # define UINT8_C(x) (x) 00279 # endif 00280 # if !defined (UINT64_MAX) 00281 # define UINT64_MAX 18446744073709551615ULL 00282 # endif 00283 # if !defined (INT64_MAX) 00284 # define INT64_MAX 9223372036854775807LL 00285 # endif 00286 # if !defined (UINT32_MAX) 00287 # define UINT32_MAX 4294967295UL 00288 # endif 00289 # if !defined (INT32_MAX) 00290 # define INT32_MAX 2147483647L 00291 # endif 00292 # if !defined (INTMAX_MAX) 00293 # define INTMAX_MAX INT64_MAX 00294 # endif 00295 # if !defined (INTMAX_MIN) 00296 # define INTMAX_MIN INT64_MIN 00297 # endif 00298 # endif 00299 #endif 00300 00301 #ifndef _PSTDINT_H_INCLUDED 00302 #define _PSTDINT_H_INCLUDED 00303 00304 #ifndef SIZE_MAX 00305 # define SIZE_MAX (~(size_t)0) 00306 #endif 00307 00308 /* 00309 * Deduce the type assignments from limits.h under the assumption that 00310 * integer sizes in bits are powers of 2, and follow the ANSI 00311 * definitions. 00312 */ 00313 00314 #ifndef UINT8_MAX 00315 # define UINT8_MAX 0xff 00316 #endif 00317 #ifndef uint8_t 00318 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S) 00319 typedef unsigned char uint8_t; 00320 # define UINT8_C(v) ((uint8_t) v) 00321 # else 00322 # error "Platform not supported" 00323 # endif 00324 #endif 00325 00326 #ifndef INT8_MAX 00327 # define INT8_MAX 0x7f 00328 #endif 00329 #ifndef INT8_MIN 00330 # define INT8_MIN INT8_C(0x80) 00331 #endif 00332 #ifndef int8_t 00333 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S) 00334 typedef signed char int8_t; 00335 # define INT8_C(v) ((int8_t) v) 00336 # else 00337 # error "Platform not supported" 00338 # endif 00339 #endif 00340 00341 #ifndef UINT16_MAX 00342 # define UINT16_MAX 0xffff 00343 #endif 00344 #ifndef uint16_t 00345 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S) 00346 typedef unsigned int uint16_t; 00347 # ifndef PRINTF_INT16_MODIFIER 00348 # define PRINTF_INT16_MODIFIER "" 00349 # endif 00350 # define UINT16_C(v) ((uint16_t) (v)) 00351 #elif (USHRT_MAX == UINT16_MAX) 00352 typedef unsigned short uint16_t; 00353 # define UINT16_C(v) ((uint16_t) (v)) 00354 # ifndef PRINTF_INT16_MODIFIER 00355 # define PRINTF_INT16_MODIFIER "h" 00356 # endif 00357 #else 00358 #error "Platform not supported" 00359 #endif 00360 #endif 00361 00362 #ifndef INT16_MAX 00363 # define INT16_MAX 0x7fff 00364 #endif 00365 #ifndef INT16_MIN 00366 # define INT16_MIN INT16_C(0x8000) 00367 #endif 00368 #ifndef int16_t 00369 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S) 00370 typedef signed int int16_t; 00371 # define INT16_C(v) ((int16_t) (v)) 00372 # ifndef PRINTF_INT16_MODIFIER 00373 # define PRINTF_INT16_MODIFIER "" 00374 # endif 00375 #elif (SHRT_MAX == INT16_MAX) 00376 typedef signed short int16_t; 00377 # define INT16_C(v) ((int16_t) (v)) 00378 # ifndef PRINTF_INT16_MODIFIER 00379 # define PRINTF_INT16_MODIFIER "h" 00380 # endif 00381 #else 00382 #error "Platform not supported" 00383 #endif 00384 #endif 00385 00386 #ifndef UINT32_MAX 00387 # define UINT32_MAX (0xffffffffUL) 00388 #endif 00389 #ifndef uint32_t 00390 #if (UINT_MAX == UINT32_MAX) && defined (__GNUC__) && (__GNUC__ > 3) 00391 typedef unsigned int uint32_t; 00392 # ifndef PRINTF_INT32_MODIFIER 00393 # define PRINTF_INT32_MODIFIER "" 00394 # endif 00395 #elif (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S) 00396 typedef unsigned long uint32_t; 00397 # define UINT32_C(v) v ## UL 00398 # ifndef PRINTF_INT32_MODIFIER 00399 # define PRINTF_INT32_MODIFIER "l" 00400 # endif 00401 #elif (UINT_MAX == UINT32_MAX) 00402 typedef unsigned int uint32_t; 00403 # ifndef PRINTF_INT32_MODIFIER 00404 # define PRINTF_INT32_MODIFIER "" 00405 # endif 00406 # define UINT32_C(v) v ## U 00407 #elif (USHRT_MAX == UINT32_MAX) 00408 typedef unsigned short uint32_t; 00409 # define UINT32_C(v) ((unsigned short) (v)) 00410 # ifndef PRINTF_INT32_MODIFIER 00411 # define PRINTF_INT32_MODIFIER "" 00412 # endif 00413 #else 00414 #error "Platform not supported" 00415 #endif 00416 #endif 00417 00418 #ifndef INT32_MAX 00419 # define INT32_MAX (0x7fffffffL) 00420 #endif 00421 #ifndef INT32_MIN 00422 # define INT32_MIN INT32_C(0x80000000) 00423 #endif 00424 #ifndef int32_t 00425 #if (INT_MAX == INT32_MAX) && defined (__GNUC__) && (__GNUC__ > 3) 00426 typedef signed int int32_t; 00427 # define INT32_C(v) v 00428 # ifndef PRINTF_INT32_MODIFIER 00429 # define PRINTF_INT32_MODIFIER "" 00430 # endif 00431 #elif (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S) 00432 typedef signed long int32_t; 00433 # define INT32_C(v) v ## L 00434 # ifndef PRINTF_INT32_MODIFIER 00435 # define PRINTF_INT32_MODIFIER "l" 00436 # endif 00437 #elif (INT_MAX == INT32_MAX) 00438 typedef signed int int32_t; 00439 # define INT32_C(v) v 00440 # ifndef PRINTF_INT32_MODIFIER 00441 # define PRINTF_INT32_MODIFIER "" 00442 # endif 00443 #elif (SHRT_MAX == INT32_MAX) 00444 typedef signed short int32_t; 00445 # define INT32_C(v) ((short) (v)) 00446 # ifndef PRINTF_INT32_MODIFIER 00447 # define PRINTF_INT32_MODIFIER "" 00448 # endif 00449 #else 00450 #error "Platform not supported" 00451 #endif 00452 #endif 00453 00454 /* 00455 * The macro stdint_int64_defined is temporarily used to record 00456 * whether or not 64 integer support is available. It must be 00457 * defined for any 64 integer extensions for new platforms that are 00458 * added. 00459 */ 00460 00461 #undef stdint_int64_defined 00462 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S) 00463 # if (__STDC__ && __STDC_VERSION >= 199901L) || 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 # endif 00473 #endif 00474 00475 #if !defined (stdint_int64_defined) 00476 # if defined(__GNUC__) && __WORDSIZE == 64 00477 # define stdint_int64_defined 00478 __extension__ typedef long int64_t; 00479 __extension__ typedef unsigned long uint64_t; 00480 # define UINT64_C(v) v ## UL 00481 # define INT64_C(v) v ## L 00482 # ifndef PRINTF_INT64_MODIFIER 00483 # define PRINTF_INT64_MODIFIER "l" 00484 # endif 00485 #elif defined(__GNUC__) 00486 # define stdint_int64_defined 00487 __extension__ typedef long long int64_t; 00488 __extension__ typedef unsigned long long uint64_t; 00489 # define UINT64_C(v) v ## ULL 00490 # define INT64_C(v) v ## LL 00491 # ifndef PRINTF_INT64_MODIFIER 00492 # define PRINTF_INT64_MODIFIER "ll" 00493 # endif 00494 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S) 00495 # define stdint_int64_defined 00496 typedef long long int64_t; 00497 typedef unsigned long long uint64_t; 00498 # define UINT64_C(v) v ## ULL 00499 # define INT64_C(v) v ## LL 00500 # ifndef PRINTF_INT64_MODIFIER 00501 # define PRINTF_INT64_MODIFIER "ll" 00502 # endif 00503 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC) 00504 # define stdint_int64_defined 00505 typedef __int64 int64_t; 00506 typedef unsigned __int64 uint64_t; 00507 # define UINT64_C(v) v ## UI64 00508 # define INT64_C(v) v ## I64 00509 # ifndef PRINTF_INT64_MODIFIER 00510 # define PRINTF_INT64_MODIFIER "I64" 00511 # endif 00512 # endif 00513 #endif 00514 00515 #if !defined (LONG_LONG_MAX) && defined (INT64_C) 00516 # define LONG_LONG_MAX INT64_C (9223372036854775807) 00517 #endif 00518 #ifndef ULONG_LONG_MAX 00519 # define ULONG_LONG_MAX UINT64_C (18446744073709551615) 00520 #endif 00521 00522 #if !defined (INT64_MAX) && defined (INT64_C) 00523 # define INT64_MAX INT64_C (9223372036854775807) 00524 #endif 00525 #if !defined (INT64_MIN) && defined (INT64_C) 00526 # define INT64_MIN INT64_C (-9223372036854775808) 00527 #endif 00528 #if !defined (UINT64_MAX) && defined (INT64_C) 00529 # define UINT64_MAX UINT64_C (18446744073709551615) 00530 #endif 00531 00532 /* 00533 * Width of hexadecimal for number field. 00534 */ 00535 00536 #ifndef PRINTF_INT64_HEX_WIDTH 00537 # define PRINTF_INT64_HEX_WIDTH "16" 00538 #endif 00539 #ifndef PRINTF_INT32_HEX_WIDTH 00540 # define PRINTF_INT32_HEX_WIDTH "8" 00541 #endif 00542 #ifndef PRINTF_INT16_HEX_WIDTH 00543 # define PRINTF_INT16_HEX_WIDTH "4" 00544 #endif 00545 #ifndef PRINTF_INT8_HEX_WIDTH 00546 # define PRINTF_INT8_HEX_WIDTH "2" 00547 #endif 00548 00549 #ifndef PRINTF_INT64_DEC_WIDTH 00550 # define PRINTF_INT64_DEC_WIDTH "20" 00551 #endif 00552 #ifndef PRINTF_INT32_DEC_WIDTH 00553 # define PRINTF_INT32_DEC_WIDTH "10" 00554 #endif 00555 #ifndef PRINTF_INT16_DEC_WIDTH 00556 # define PRINTF_INT16_DEC_WIDTH "5" 00557 #endif 00558 #ifndef PRINTF_INT8_DEC_WIDTH 00559 # define PRINTF_INT8_DEC_WIDTH "3" 00560 #endif 00561 00562 /* 00563 * Ok, lets not worry about 128 bit integers for now. Moore's law says 00564 * we don't need to worry about that until about 2040 at which point 00565 * we'll have bigger things to worry about. 00566 */ 00567 00568 #ifdef stdint_int64_defined 00569 typedef int64_t intmax_t; 00570 typedef uint64_t uintmax_t; 00571 # define INTMAX_MAX INT64_MAX 00572 # define INTMAX_MIN INT64_MIN 00573 # define UINTMAX_MAX UINT64_MAX 00574 # define UINTMAX_C(v) UINT64_C(v) 00575 # define INTMAX_C(v) INT64_C(v) 00576 # ifndef PRINTF_INTMAX_MODIFIER 00577 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER 00578 # endif 00579 # ifndef PRINTF_INTMAX_HEX_WIDTH 00580 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH 00581 # endif 00582 # ifndef PRINTF_INTMAX_DEC_WIDTH 00583 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH 00584 # endif 00585 #else 00586 typedef int32_t intmax_t; 00587 typedef uint32_t uintmax_t; 00588 # define INTMAX_MAX INT32_MAX 00589 # define UINTMAX_MAX UINT32_MAX 00590 # define UINTMAX_C(v) UINT32_C(v) 00591 # define INTMAX_C(v) INT32_C(v) 00592 # ifndef PRINTF_INTMAX_MODIFIER 00593 # define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER 00594 # endif 00595 # ifndef PRINTF_INTMAX_HEX_WIDTH 00596 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH 00597 # endif 00598 # ifndef PRINTF_INTMAX_DEC_WIDTH 00599 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH 00600 # endif 00601 #endif 00602 00603 /* 00604 * Because this file currently only supports platforms which have 00605 * precise powers of 2 as bit sizes for the default integers, the 00606 * least definitions are all trivial. Its possible that a future 00607 * version of this file could have different definitions. 00608 */ 00609 00610 #ifndef stdint_least_defined 00611 typedef int8_t int_least8_t; 00612 typedef uint8_t uint_least8_t; 00613 typedef int16_t int_least16_t; 00614 typedef uint16_t uint_least16_t; 00615 typedef int32_t int_least32_t; 00616 typedef uint32_t uint_least32_t; 00617 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER 00618 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER 00619 # define UINT_LEAST8_MAX UINT8_MAX 00620 # define INT_LEAST8_MAX INT8_MAX 00621 # define UINT_LEAST16_MAX UINT16_MAX 00622 # define INT_LEAST16_MAX INT16_MAX 00623 # define UINT_LEAST32_MAX UINT32_MAX 00624 # define INT_LEAST32_MAX INT32_MAX 00625 # define INT_LEAST8_MIN INT8_MIN 00626 # define INT_LEAST16_MIN INT16_MIN 00627 # define INT_LEAST32_MIN INT32_MIN 00628 # ifdef stdint_int64_defined 00629 typedef int64_t int_least64_t; 00630 typedef uint64_t uint_least64_t; 00631 # define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER 00632 # define UINT_LEAST64_MAX UINT64_MAX 00633 # define INT_LEAST64_MAX INT64_MAX 00634 # define INT_LEAST64_MIN INT64_MIN 00635 # endif 00636 #endif 00637 #undef stdint_least_defined 00638 00639 /* 00640 * The ANSI C committee pretending to know or specify anything about 00641 * performance is the epitome of misguided arrogance. The mandate of 00642 * this file is to *ONLY* ever support that absolute minimum 00643 * definition of the fast integer types, for compatibility purposes. 00644 * No extensions, and no attempt to suggest what may or may not be a 00645 * faster integer type will ever be made in this file. Developers are 00646 * warned to stay away from these types when using this or any other 00647 * stdint.h. 00648 */ 00649 00650 #ifndef int_fast8_t 00651 typedef int_least8_t int_fast8_t; 00652 #endif 00653 #ifndef uint_fast8_t 00654 typedef uint_least8_t uint_fast8_t; 00655 #endif 00656 #ifndef int_fast16_t 00657 typedef int_least16_t int_fast16_t; 00658 #endif 00659 #ifndef uint_fast16_t 00660 typedef uint_least16_t uint_fast16_t; 00661 #endif 00662 #ifndef int_fast32_t 00663 typedef int_least32_t int_fast32_t; 00664 #endif 00665 #ifndef uint_fast32_t 00666 typedef uint_least32_t uint_fast32_t; 00667 #endif 00668 #define UINT_FAST8_MAX UINT_LEAST8_MAX 00669 #define INT_FAST8_MAX INT_LEAST8_MAX 00670 #define UINT_FAST16_MAX UINT_LEAST16_MAX 00671 #define INT_FAST16_MAX INT_LEAST16_MAX 00672 #define UINT_FAST32_MAX UINT_LEAST32_MAX 00673 #define INT_FAST32_MAX INT_LEAST32_MAX 00674 #define INT_FAST8_MIN INT_LEAST8_MIN 00675 #define INT_FAST16_MIN INT_LEAST16_MIN 00676 #define INT_FAST32_MIN INT_LEAST32_MIN 00677 #ifdef stdint_int64_defined 00678 typedef int_least64_t int_fast64_t; 00679 typedef uint_least64_t uint_fast64_t; 00680 # define UINT_FAST64_MAX UINT_LEAST64_MAX 00681 # define INT_FAST64_MAX INT_LEAST64_MAX 00682 # define INT_FAST64_MIN INT_LEAST64_MIN 00683 #endif 00684 00685 #undef stdint_int64_defined 00686 00687 /* 00688 * Whatever piecemeal, per compiler thing we can do about the wchar_t 00689 * type limits. 00690 */ 00691 00692 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__) 00693 # include <wchar.h> 00694 # ifndef WCHAR_MIN 00695 # define WCHAR_MIN 0 00696 # endif 00697 # ifndef WCHAR_MAX 00698 # define WCHAR_MAX ((wchar_t)-1) 00699 # endif 00700 #endif 00701 00702 /* 00703 * Whatever piecemeal, per compiler/platform thing we can do about the 00704 * (u)intptr_t types and limits. 00705 */ 00706 00707 #if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED) 00708 # define STDINT_H_UINTPTR_T_DEFINED 00709 #endif 00710 00711 #ifndef STDINT_H_UINTPTR_T_DEFINED 00712 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) 00713 # define stdint_intptr_bits 64 00714 # elif defined (__WATCOMC__) || defined (__TURBOC__) 00715 # if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__) 00716 # define stdint_intptr_bits 16 00717 # else 00718 # define stdint_intptr_bits 32 00719 # endif 00720 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32) 00721 # define stdint_intptr_bits 32 00722 # elif defined (__INTEL_COMPILER) 00723 /* TODO -- what will Intel do about x86-64? */ 00724 # endif 00725 00726 # ifdef stdint_intptr_bits 00727 # define stdint_intptr_glue3_i(a,b,c) a##b##c 00728 # define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c) 00729 # ifndef PRINTF_INTPTR_MODIFIER 00730 # define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER) 00731 # endif 00732 # ifndef PTRDIFF_MAX 00733 # define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) 00734 # endif 00735 # ifndef PTRDIFF_MIN 00736 # define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) 00737 # endif 00738 # ifndef UINTPTR_MAX 00739 # define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX) 00740 # endif 00741 # ifndef INTPTR_MAX 00742 # define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) 00743 # endif 00744 # ifndef INTPTR_MIN 00745 # define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) 00746 # endif 00747 # ifndef INTPTR_C 00748 # define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x) 00749 # endif 00750 # ifndef UINTPTR_C 00751 # define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x) 00752 # endif 00753 typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t; 00754 typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t; 00755 # else 00756 /* TODO -- This following is likely wrong for some platforms, and does 00757 nothing for the definition of uintptr_t. */ 00758 typedef ptrdiff_t intptr_t; 00759 # endif 00760 # define STDINT_H_UINTPTR_T_DEFINED 00761 #endif 00762 00763 /* 00764 * Assumes sig_atomic_t is signed and we have a 2s complement machine. 00765 */ 00766 00767 #ifndef SIG_ATOMIC_MAX 00768 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1) 00769 #endif 00770 00771 #endif 00772 00773 #ifndef _CMT_MONOLITHIC 00774 00775 #if defined (__TEST_PSTDINT_FOR_CORRECTNESS) 00776 00777 /* 00778 * Please compile with the maximum warning settings to make sure macros are not 00779 * defined more than once. 00780 */ 00781 00782 #include <stdlib.h> 00783 #include <stdio.h> 00784 #include <string.h> 00785 00786 #define glue3_aux(x,y,z) x ## y ## z 00787 #define glue3(x,y,z) glue3_aux(x,y,z) 00788 00789 #define DECLU(bits) glue3(uint,bits,_t) glue3(u,bits,=) glue3(UINT,bits,_C) (0); 00790 #define DECLI(bits) glue3(int,bits,_t) glue3(i,bits,=) glue3(INT,bits,_C) (0); 00791 00792 #define DECL(us,bits) glue3(DECL,us,) (bits) 00793 00794 #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) 00795 00796 int main () { 00797 DECL(I,8) 00798 DECL(U,8) 00799 DECL(I,16) 00800 DECL(U,16) 00801 DECL(I,32) 00802 DECL(U,32) 00803 #ifdef INT64_MAX 00804 DECL(I,64) 00805 DECL(U,64) 00806 #endif 00807 intmax_t imax = INTMAX_C(0); 00808 uintmax_t umax = UINTMAX_C(0); 00809 char str0[256], str1[256]; 00810 00811 sprintf (str0, "%d %x\n", 0, ~0); 00812 00813 sprintf (str1, "%d %x\n", i8, ~0); 00814 if (0 != strcmp (str0, str1)) printf ("Something wrong with i8 : %s\n", str1); 00815 sprintf (str1, "%u %x\n", u8, ~0); 00816 if (0 != strcmp (str0, str1)) printf ("Something wrong with u8 : %s\n", str1); 00817 sprintf (str1, "%d %x\n", i16, ~0); 00818 if (0 != strcmp (str0, str1)) printf ("Something wrong with i16 : %s\n", str1); 00819 sprintf (str1, "%u %x\n", u16, ~0); 00820 if (0 != strcmp (str0, str1)) printf ("Something wrong with u16 : %s\n", str1); 00821 sprintf (str1, "%" PRINTF_INT32_MODIFIER "d %x\n", i32, ~0); 00822 if (0 != strcmp (str0, str1)) printf ("Something wrong with i32 : %s\n", str1); 00823 sprintf (str1, "%" PRINTF_INT32_MODIFIER "u %x\n", u32, ~0); 00824 if (0 != strcmp (str0, str1)) printf ("Something wrong with u32 : %s\n", str1); 00825 #ifdef INT64_MAX 00826 sprintf (str1, "%" PRINTF_INT64_MODIFIER "d %x\n", i64, ~0); 00827 if (0 != strcmp (str0, str1)) printf ("Something wrong with i64 : %s\n", str1); 00828 #endif 00829 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "d %x\n", imax, ~0); 00830 if (0 != strcmp (str0, str1)) printf ("Something wrong with imax : %s\n", str1); 00831 sprintf (str1, "%" PRINTF_INTMAX_MODIFIER "u %x\n", umax, ~0); 00832 if (0 != strcmp (str0, str1)) printf ("Something wrong with umax : %s\n", str1); 00833 00834 TESTUMAX(8); 00835 TESTUMAX(16); 00836 TESTUMAX(32); 00837 #ifdef INT64_MAX 00838 TESTUMAX(64); 00839 #endif 00840 00841 return EXIT_SUCCESS; 00842 } 00843 00844 #endif 00845 #endif // #ifndef _CMT_MONOLITHIC