1 /* A portable stdint.h 2 * 3 * Copyright (c) 2005 Paul Hsieh 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * Redistributions in binary form must not misrepresent the orignal 13 * source in the documentation and/or other materials provided 14 * with the distribution. 15 * 16 * The names of the authors not its contributors may be used to 17 * endorse or promote products derived from this software without 18 * specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 31 * OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 **************************************************************************** 34 * 35 * Version 0.1.5 36 * 37 * The ANSI C standard committee, for the C99 standard, specified the 38 * inclusion of a new standard include file called stdint.h. This is 39 * a very useful and long desired include file which contains several 40 * very precise definitions for integer scalar types that is 41 * critically important for making portable several classes of 42 * applications including cryptography, hashing, variable length 43 * integer libraries and so on. But for most developers its likely 44 * useful just for programming sanity. 45 * 46 * The problem is that most compiler vendors have decided not to 47 * implement the C99 standard, and the next C++ language standard 48 * (which has a lot more mindshare these days) will be a long time in 49 * coming and its unknown whether or not it will include stdint.h or 50 * how much adoption it will have. Either way, it will be a long time 51 * before all compilers come with a stdint.h and it also does nothing 52 * for the extremely large number of compilers available today which 53 * do not include this file, or anything comparable to it. 54 * 55 * So that's what this file is all about. Its an attempt to build a 56 * single universal include file that works on as many platforms as 57 * possible to deliver what stdint.h is supposed to. A few things 58 * that should be noted about this file: 59 * 60 * 1) It is not guaranteed to be portable and/or present an identical 61 * interface on all platforms. The extreme variability of the 62 * ANSI C standard makes this an impossibility right from the 63 * very get go. Its really only meant to be useful for the vast 64 * majority of platforms that possess the capability of 65 * implementing usefuly and precisely defined, standard sized 66 * integer scalars. Systems which are not intrinsically 2s 67 * complement may produce invalid constants. 68 * 69 * 2) There is an unavoidable use of non-reserved symbols. 70 * 71 * 3) Other standard include files are invoked. 72 * 73 * 4) This file may come in conflict with future platforms that do 74 * include stdint.h. The hope is that one or the other can be 75 * used with no real difference. 76 * 77 * 5) In the current verison, if your platform can't represent 78 * int32_t, int16_t and int8_t, it just dumps out with a compiler 79 * error. 80 * 81 * 6) 64 bit integers may or may not be defined. Test for their 82 * presence with the test: #ifdef INT64_MAX or #ifdef UINT64_MAX. 83 * Note that this is different from the C99 specification which 84 * requires the existence of 64 bit support in the compiler. If 85 * this is not defined for your platform, yet it is capable of 86 * dealing with 64 bits then it is because this file has not yet 87 * been extended to cover all of your system's capabilities. 88 * 89 * 7) (u)intptr_t may or may not be defined. Test for its presence 90 * with the test: #ifdef PTRDIFF_MAX. If this is not defined 91 * for your platform, then it is because this file has not yet 92 * been extended to cover all of your system's capabilities, not 93 * because its optional. 94 * 95 * 8) The following might not been defined even if your platform is 96 * capable of defining it: 97 * 98 * WCHAR_MIN 99 * WCHAR_MAX 100 * (u)int64_t 101 * PTRDIFF_MIN 102 * PTRDIFF_MAX 103 * (u)intptr_t 104 * 105 * 9) The following have not been defined: 106 * 107 * WINT_MIN 108 * WINT_MAX 109 * 110 * 10) The criteria for defining (u)int_least(*)_t isn't clear, 111 * except for systems which don't have a type that precisely 112 * defined 8, 16, or 32 bit types (which this include file does 113 * not support anyways). Default definitions have been given. 114 * 115 * 11) The criteria for defining (u)int_fast(*)_t isn't something I 116 * would trust to any particular compiler vendor or the ANSI C 117 * comittee. It is well known that "compatible systems" are 118 * commonly created that have very different performance 119 * characteristics from the systems they are compatible with, 120 * especially those whose vendors make both the compiler and the 121 * system. Default definitions have been given, but its strongly 122 * recommended that users never use these definitions for any 123 * reason (they do *NOT* deliver any serious guarantee of 124 * improved performance -- not in this file, nor any vendor's 125 * stdint.h). 126 * 127 * 12) The following macros: 128 * 129 * PRINTF_INTMAX_MODIFIER 130 * PRINTF_INT64_MODIFIER 131 * PRINTF_INT32_MODIFIER 132 * PRINTF_INT16_MODIFIER 133 * PRINTF_LEAST64_MODIFIER 134 * PRINTF_LEAST32_MODIFIER 135 * PRINTF_LEAST16_MODIFIER 136 * PRINTF_INTPTR_MODIFIER 137 * 138 * are strings which have been defined as the modifiers required 139 * for the "d", "u" and "x" printf formats to correctly output 140 * (u)intmax_t, (u)int64_t, (u)int32_t, (u)int16_t, (u)least64_t, 141 * (u)least32_t, (u)least16_t and (u)intptr_t types respectively. 142 * PRINTF_INTPTR_MODIFIER is not defined for some systems which 143 * provide their own stdint.h. PRINTF_INT64_MODIFIER is not 144 * defined if INT64_MAX is not defined. These are an extension 145 * beyond what C99 specifies must be in stdint.h. 146 * 147 * In addition, the following macros are defined: 148 * 149 * PRINTF_INTMAX_HEX_WIDTH 150 * PRINTF_INT64_HEX_WIDTH 151 * PRINTF_INT32_HEX_WIDTH 152 * PRINTF_INT16_HEX_WIDTH 153 * PRINTF_INT8_HEX_WIDTH 154 * PRINTF_INTMAX_DEC_WIDTH 155 * PRINTF_INT64_DEC_WIDTH 156 * PRINTF_INT32_DEC_WIDTH 157 * PRINTF_INT16_DEC_WIDTH 158 * PRINTF_INT8_DEC_WIDTH 159 * 160 * Which specifies the maximum number of characters required to 161 * print the number of that type in either hexadecimal or decimal. 162 * These are an extension beyond what C99 specifies must be in 163 * stdint.h. 164 * 165 * Compilers tested (all with 0 warnings at their highest respective 166 * settings): Borland Turbo C 2.0, WATCOM C/C++ 11.0 (16 bits and 32 167 * bits), Microsoft Visual C++ 6.0 (32 bit), Microsoft Visual Studio 168 * .net (VC7), Intel C++ 4.0, GNU gcc v3.3.3 169 * 170 * This file should be considered a work in progress. Suggestions for 171 * improvements, especially those which increase coverage are strongly 172 * encouraged. 173 * 174 * Acknowledgements 175 * 176 * The following people have made significant contributions to the 177 * development and testing of this file: 178 * 179 * Chris Howie 180 * John Steele Scott 181 * 182 */ 183 184 #include <stddef.h> 185 #include <limits.h> 186 #include <signal.h> 187 188 /* 189 * For gcc with _STDINT_H, fill in the PRINTF_INT*_MODIFIER macros, and 190 * do nothing else. 191 */ 192 193 #if ((defined(__STDC__) && __STDC__ && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && defined(_STDINT_H))) && !defined (_PSTDINT_H_INCLUDED) 194 #include <stdint.h> 195 #define _PSTDINT_H_INCLUDED 196 # ifndef PRINTF_INT64_MODIFIER 197 # define PRINTF_INT64_MODIFIER "ll" 198 # endif 199 # ifndef PRINTF_INT32_MODIFIER 200 # define PRINTF_INT32_MODIFIER "l" 201 # endif 202 # ifndef PRINTF_INT16_MODIFIER 203 # define PRINTF_INT16_MODIFIER "h" 204 # endif 205 # ifndef PRINTF_INTMAX_MODIFIER 206 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER 207 # endif 208 # ifndef PRINTF_INT64_HEX_WIDTH 209 # define PRINTF_INT64_HEX_WIDTH "16" 210 # endif 211 # ifndef PRINTF_INT32_HEX_WIDTH 212 # define PRINTF_INT32_HEX_WIDTH "8" 213 # endif 214 # ifndef PRINTF_INT16_HEX_WIDTH 215 # define PRINTF_INT16_HEX_WIDTH "4" 216 # endif 217 # ifndef PRINTF_INT8_HEX_WIDTH 218 # define PRINTF_INT8_HEX_WIDTH "2" 219 # endif 220 # ifndef PRINTF_INT64_DEC_WIDTH 221 # define PRINTF_INT64_DEC_WIDTH "20" 222 # endif 223 # ifndef PRINTF_INT32_DEC_WIDTH 224 # define PRINTF_INT32_DEC_WIDTH "10" 225 # endif 226 # ifndef PRINTF_INT16_DEC_WIDTH 227 # define PRINTF_INT16_DEC_WIDTH "5" 228 # endif 229 # ifndef PRINTF_INT8_DEC_WIDTH 230 # define PRINTF_INT8_DEC_WIDTH "3" 231 # endif 232 # ifndef PRINTF_INTMAX_HEX_WIDTH 233 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH 234 # endif 235 # ifndef PRINTF_INTMAX_DEC_WIDTH 236 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH 237 # endif 238 #endif 239 240 #ifndef _PSTDINT_H_INCLUDED 241 #define _PSTDINT_H_INCLUDED 242 243 #ifndef SIZE_MAX 244 # define SIZE_MAX (~(size_t)0) 245 #endif 246 247 /* 248 * Deduce the type assignments from limits.h under the assumption that 249 * integer sizes in bits are powers of 2, and follow the ANSI 250 * definitions. 251 */ 252 253 #ifndef UINT8_MAX 254 # define UINT8_MAX 0xff 255 #endif 256 #ifndef uint8_t 257 # if (UCHAR_MAX == UINT8_MAX) || defined (S_SPLINT_S) 258 typedef unsigned char uint8_t; 259 # define UINT8_C(v) ((uint8_t) v) 260 # else 261 # error "Platform not supported" 262 # endif 263 #endif 264 265 #ifndef INT8_MAX 266 # define INT8_MAX 0x7f 267 #endif 268 #ifndef INT8_MIN 269 # define INT8_MIN INT8_C(0x80) 270 #endif 271 #ifndef int8_t 272 # if (SCHAR_MAX == INT8_MAX) || defined (S_SPLINT_S) 273 typedef signed char int8_t; 274 # define INT8_C(v) ((int8_t) v) 275 # else 276 # error "Platform not supported" 277 # endif 278 #endif 279 280 #ifndef UINT16_MAX 281 # define UINT16_MAX 0xffff 282 #endif 283 #ifndef uint16_t 284 #if (UINT_MAX == UINT16_MAX) || defined (S_SPLINT_S) 285 typedef unsigned int uint16_t; 286 # ifndef PRINTF_INT16_MODIFIER 287 # define PRINTF_INT16_MODIFIER "" 288 # endif 289 # define UINT16_C(v) ((uint16_t) (v)) 290 #elif (USHRT_MAX == UINT16_MAX) 291 typedef unsigned short uint16_t; 292 # define UINT16_C(v) ((uint16_t) (v)) 293 # ifndef PRINTF_INT16_MODIFIER 294 # define PRINTF_INT16_MODIFIER "h" 295 # endif 296 #else 297 #error "Platform not supported" 298 #endif 299 #endif 300 301 #ifndef INT16_MAX 302 # define INT16_MAX 0x7fff 303 #endif 304 #ifndef INT16_MIN 305 # define INT16_MIN INT16_C(0x8000) 306 #endif 307 #ifndef int16_t 308 #if (INT_MAX == INT16_MAX) || defined (S_SPLINT_S) 309 typedef signed int int16_t; 310 # define INT16_C(v) ((int16_t) (v)) 311 # ifndef PRINTF_INT16_MODIFIER 312 # define PRINTF_INT16_MODIFIER "" 313 # endif 314 #elif (SHRT_MAX == INT16_MAX) 315 typedef signed short int16_t; 316 # define INT16_C(v) ((int16_t) (v)) 317 # ifndef PRINTF_INT16_MODIFIER 318 # define PRINTF_INT16_MODIFIER "h" 319 # endif 320 #else 321 #error "Platform not supported" 322 #endif 323 #endif 324 325 #ifndef UINT32_MAX 326 # define UINT32_MAX (0xffffffffUL) 327 #endif 328 #ifndef uint32_t 329 #if (ULONG_MAX == UINT32_MAX) || defined (S_SPLINT_S) 330 typedef unsigned long uint32_t; 331 # define UINT32_C(v) v ## UL 332 # ifndef PRINTF_INT32_MODIFIER 333 # define PRINTF_INT32_MODIFIER "l" 334 # endif 335 #elif (UINT_MAX == UINT32_MAX) 336 typedef unsigned int uint32_t; 337 # ifndef PRINTF_INT32_MODIFIER 338 # define PRINTF_INT32_MODIFIER "" 339 # endif 340 # define UINT32_C(v) v ## U 341 #elif (USHRT_MAX == UINT32_MAX) 342 typedef unsigned short uint32_t; 343 # define UINT32_C(v) ((unsigned short) (v)) 344 # ifndef PRINTF_INT32_MODIFIER 345 # define PRINTF_INT32_MODIFIER "" 346 # endif 347 #else 348 #error "Platform not supported" 349 #endif 350 #endif 351 352 #ifndef INT32_MAX 353 # define INT32_MAX (0x7fffffffL) 354 #endif 355 #ifndef INT32_MIN 356 # define INT32_MIN INT32_C(0x80000000) 357 #endif 358 #ifndef int32_t 359 #if (LONG_MAX == INT32_MAX) || defined (S_SPLINT_S) 360 typedef signed long int32_t; 361 # define INT32_C(v) v ## L 362 # ifndef PRINTF_INT32_MODIFIER 363 # define PRINTF_INT32_MODIFIER "l" 364 # endif 365 #elif (INT_MAX == INT32_MAX) 366 typedef signed int int32_t; 367 # define INT32_C(v) v 368 # ifndef PRINTF_INT32_MODIFIER 369 # define PRINTF_INT32_MODIFIER "" 370 # endif 371 #elif (SHRT_MAX == INT32_MAX) 372 typedef signed short int32_t; 373 # define INT32_C(v) ((short) (v)) 374 # ifndef PRINTF_INT32_MODIFIER 375 # define PRINTF_INT32_MODIFIER "" 376 # endif 377 #else 378 #error "Platform not supported" 379 #endif 380 #endif 381 382 /* 383 * The macro stdint_int64_defined is temporarily used to record 384 * whether or not 64 integer support is available. It must be 385 * defined for any 64 integer extensions for new platforms that are 386 * added. 387 */ 388 389 #undef stdint_int64_defined 390 #if (defined(__STDC__) && defined(__STDC_VERSION__)) || defined (S_SPLINT_S) 391 # if (__STDC__ && __STDC_VERSION >= 199901L) || defined (S_SPLINT_S) 392 # define stdint_int64_defined 393 typedef long long int64_t; 394 typedef unsigned long long uint64_t; 395 # define UINT64_C(v) v ## ULL 396 # define INT64_C(v) v ## LL 397 # ifndef PRINTF_INT64_MODIFIER 398 # define PRINTF_INT64_MODIFIER "ll" 399 # endif 400 # endif 401 #endif 402 403 #if !defined (stdint_int64_defined) 404 # if defined(__GNUC__) 405 # define stdint_int64_defined 406 __extension__ typedef long long int64_t; 407 __extension__ typedef unsigned long long uint64_t; 408 # define UINT64_C(v) v ## ULL 409 # define INT64_C(v) v ## LL 410 # ifndef PRINTF_INT64_MODIFIER 411 # define PRINTF_INT64_MODIFIER "ll" 412 # endif 413 # elif defined(__MWERKS__) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || defined (__APPLE_CC__) || defined (_LONG_LONG) || defined (_CRAYC) || defined (S_SPLINT_S) 414 # define stdint_int64_defined 415 typedef long long int64_t; 416 typedef unsigned long long uint64_t; 417 # define UINT64_C(v) v ## ULL 418 # define INT64_C(v) v ## LL 419 # ifndef PRINTF_INT64_MODIFIER 420 # define PRINTF_INT64_MODIFIER "ll" 421 # endif 422 # elif (defined(__WATCOMC__) && defined(__WATCOM_INT64__)) || (defined(_MSC_VER) && _INTEGRAL_MAX_BITS >= 64) || (defined (__BORLANDC__) && __BORLANDC__ > 0x460) || defined (__alpha) || defined (__DECC) 423 # define stdint_int64_defined 424 typedef __int64 int64_t; 425 typedef unsigned __int64 uint64_t; 426 # define UINT64_C(v) v ## UI64 427 # define INT64_C(v) v ## I64 428 # ifndef PRINTF_INT64_MODIFIER 429 # define PRINTF_INT64_MODIFIER "I64" 430 # endif 431 # endif 432 #endif 433 434 #if !defined (LONG_LONG_MAX) && defined (INT64_C) 435 # define LONG_LONG_MAX INT64_C (9223372036854775807) 436 #endif 437 #ifndef ULONG_LONG_MAX 438 # define ULONG_LONG_MAX UINT64_C (18446744073709551615) 439 #endif 440 441 #if !defined (INT64_MAX) && defined (INT64_C) 442 # define INT64_MAX INT64_C (9223372036854775807) 443 #endif 444 #if !defined (INT64_MIN) && defined (INT64_C) 445 # define INT64_MIN INT64_C (-9223372036854775808) 446 #endif 447 #if !defined (UINT64_MAX) && defined (INT64_C) 448 # define UINT64_MAX UINT64_C (18446744073709551615) 449 #endif 450 451 /* 452 * Width of hexadecimal for number field. 453 */ 454 455 #ifndef PRINTF_INT64_HEX_WIDTH 456 # define PRINTF_INT64_HEX_WIDTH "16" 457 #endif 458 #ifndef PRINTF_INT32_HEX_WIDTH 459 # define PRINTF_INT32_HEX_WIDTH "8" 460 #endif 461 #ifndef PRINTF_INT16_HEX_WIDTH 462 # define PRINTF_INT16_HEX_WIDTH "4" 463 #endif 464 #ifndef PRINTF_INT8_HEX_WIDTH 465 # define PRINTF_INT8_HEX_WIDTH "2" 466 #endif 467 468 #ifndef PRINTF_INT64_DEC_WIDTH 469 # define PRINTF_INT64_DEC_WIDTH "20" 470 #endif 471 #ifndef PRINTF_INT32_DEC_WIDTH 472 # define PRINTF_INT32_DEC_WIDTH "10" 473 #endif 474 #ifndef PRINTF_INT16_DEC_WIDTH 475 # define PRINTF_INT16_DEC_WIDTH "5" 476 #endif 477 #ifndef PRINTF_INT8_DEC_WIDTH 478 # define PRINTF_INT8_DEC_WIDTH "3" 479 #endif 480 481 /* 482 * Ok, lets not worry about 128 bit integers for now. Moore's law says 483 * we don't need to worry about that until about 2040 at which point 484 * we'll have bigger things to worry about. 485 */ 486 487 #ifdef stdint_int64_defined 488 typedef int64_t intmax_t; 489 typedef uint64_t uintmax_t; 490 # define INTMAX_MAX INT64_MAX 491 # define INTMAX_MIN INT64_MIN 492 # define UINTMAX_MAX UINT64_MAX 493 # define UINTMAX_C(v) UINT64_C(v) 494 # define INTMAX_C(v) INT64_C(v) 495 # ifndef PRINTF_INTMAX_MODIFIER 496 # define PRINTF_INTMAX_MODIFIER PRINTF_INT64_MODIFIER 497 # endif 498 # ifndef PRINTF_INTMAX_HEX_WIDTH 499 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT64_HEX_WIDTH 500 # endif 501 # ifndef PRINTF_INTMAX_DEC_WIDTH 502 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT64_DEC_WIDTH 503 # endif 504 #else 505 typedef int32_t intmax_t; 506 typedef uint32_t uintmax_t; 507 # define INTMAX_MAX INT32_MAX 508 # define UINTMAX_MAX UINT32_MAX 509 # define UINTMAX_C(v) UINT32_C(v) 510 # define INTMAX_C(v) INT32_C(v) 511 # ifndef PRINTF_INTMAX_MODIFIER 512 # define PRINTF_INTMAX_MODIFIER PRINTF_INT32_MODIFIER 513 # endif 514 # ifndef PRINTF_INTMAX_HEX_WIDTH 515 # define PRINTF_INTMAX_HEX_WIDTH PRINTF_INT32_HEX_WIDTH 516 # endif 517 # ifndef PRINTF_INTMAX_DEC_WIDTH 518 # define PRINTF_INTMAX_DEC_WIDTH PRINTF_INT32_DEC_WIDTH 519 # endif 520 #endif 521 522 /* 523 * Because this file currently only supports platforms which have 524 * precise powers of 2 as bit sizes for the default integers, the 525 * least definitions are all trivial. Its possible that a future 526 * version of this file could have different definitions. 527 */ 528 529 #ifndef stdint_least_defined 530 typedef int8_t int_least8_t; 531 typedef uint8_t uint_least8_t; 532 typedef int16_t int_least16_t; 533 typedef uint16_t uint_least16_t; 534 typedef int32_t int_least32_t; 535 typedef uint32_t uint_least32_t; 536 # define PRINTF_LEAST32_MODIFIER PRINTF_INT32_MODIFIER 537 # define PRINTF_LEAST16_MODIFIER PRINTF_INT16_MODIFIER 538 # define UINT_LEAST8_MAX UINT8_MAX 539 # define INT_LEAST8_MAX INT8_MAX 540 # define UINT_LEAST16_MAX UINT16_MAX 541 # define INT_LEAST16_MAX INT16_MAX 542 # define UINT_LEAST32_MAX UINT32_MAX 543 # define INT_LEAST32_MAX INT32_MAX 544 # define INT_LEAST8_MIN INT8_MIN 545 # define INT_LEAST16_MIN INT16_MIN 546 # define INT_LEAST32_MIN INT32_MIN 547 # ifdef stdint_int64_defined 548 typedef int64_t int_least64_t; 549 typedef uint64_t uint_least64_t; 550 # define PRINTF_LEAST64_MODIFIER PRINTF_INT64_MODIFIER 551 # define UINT_LEAST64_MAX UINT64_MAX 552 # define INT_LEAST64_MAX INT64_MAX 553 # define INT_LEAST64_MIN INT64_MIN 554 # endif 555 #endif 556 #undef stdint_least_defined 557 558 /* 559 * The ANSI C committee pretending to know or specify anything about 560 * performance is the epitome of misguided arrogance. The mandate of 561 * this file is to *ONLY* ever support that absolute minimum 562 * definition of the fast integer types, for compatibility purposes. 563 * No extensions, and no attempt to suggest what may or may not be a 564 * faster integer type will ever be made in this file. Developers are 565 * warned to stay away from these types when using this or any other 566 * stdint.h. 567 */ 568 569 typedef int_least8_t int_fast8_t; 570 typedef uint_least8_t uint_fast8_t; 571 typedef int_least16_t int_fast16_t; 572 typedef uint_least16_t uint_fast16_t; 573 typedef int_least32_t int_fast32_t; 574 typedef uint_least32_t uint_fast32_t; 575 #define UINT_FAST8_MAX UINT_LEAST8_MAX 576 #define INT_FAST8_MAX INT_LEAST8_MAX 577 #define UINT_FAST16_MAX UINT_LEAST16_MAX 578 #define INT_FAST16_MAX INT_LEAST16_MAX 579 #define UINT_FAST32_MAX UINT_LEAST32_MAX 580 #define INT_FAST32_MAX INT_LEAST32_MAX 581 #define INT_FAST8_MIN IN_LEASTT8_MIN 582 #define INT_FAST16_MIN INT_LEAST16_MIN 583 #define INT_FAST32_MIN INT_LEAST32_MIN 584 #ifdef stdint_int64_defined 585 typedef int_least64_t int_fast64_t; 586 typedef uint_least64_t uint_fast64_t; 587 # define UINT_FAST64_MAX UINT_LEAST64_MAX 588 # define INT_FAST64_MAX INT_LEAST64_MAX 589 # define INT_FAST64_MIN INT_LEAST64_MIN 590 #endif 591 592 #undef stdint_int64_defined 593 594 /* 595 * Whatever piecemeal, per compiler thing we can do about the wchar_t 596 * type limits. 597 */ 598 599 #if defined(__WATCOMC__) || defined(_MSC_VER) || defined (__GNUC__) && !defined (__EMX__) 600 # include <wchar.h> 601 # ifndef WCHAR_MIN 602 # define WCHAR_MIN 0 603 # endif 604 # ifndef WCHAR_MAX 605 # define WCHAR_MAX ((wchar_t)-1) 606 # endif 607 #endif 608 609 /* 610 * Whatever piecemeal, per compiler/platform thing we can do about the 611 * (u)intptr_t types and limits. 612 */ 613 614 #if defined (_MSC_VER) && defined (_UINTPTR_T_DEFINED) 615 # define STDINT_H_UINTPTR_T_DEFINED 616 #endif 617 618 #ifndef STDINT_H_UINTPTR_T_DEFINED 619 # if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) || defined (_WIN64) 620 # define stdint_intptr_bits 64 621 # elif defined (__WATCOMC__) || defined (__TURBOC__) 622 # if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__) 623 # define stdint_intptr_bits 16 624 # else 625 # define stdint_intptr_bits 32 626 # endif 627 # elif defined (__i386__) || defined (_WIN32) || defined (WIN32) 628 # define stdint_intptr_bits 32 629 # elif defined (__INTEL_COMPILER) 630 /* TODO -- what will Intel do about x86-64? */ 631 # endif 632 633 # ifdef stdint_intptr_bits 634 # define stdint_intptr_glue3_i(a,b,c) a##b##c 635 # define stdint_intptr_glue3(a,b,c) stdint_intptr_glue3_i(a,b,c) 636 # ifndef PRINTF_INTPTR_MODIFIER 637 # define PRINTF_INTPTR_MODIFIER stdint_intptr_glue3(PRINTF_INT,stdint_intptr_bits,_MODIFIER) 638 # endif 639 # ifndef PTRDIFF_MAX 640 # define PTRDIFF_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) 641 # endif 642 # ifndef PTRDIFF_MIN 643 # define PTRDIFF_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) 644 # endif 645 # ifndef UINTPTR_MAX 646 # define UINTPTR_MAX stdint_intptr_glue3(UINT,stdint_intptr_bits,_MAX) 647 # endif 648 # ifndef INTPTR_MAX 649 # define INTPTR_MAX stdint_intptr_glue3(INT,stdint_intptr_bits,_MAX) 650 # endif 651 # ifndef INTPTR_MIN 652 # define INTPTR_MIN stdint_intptr_glue3(INT,stdint_intptr_bits,_MIN) 653 # endif 654 # ifndef INTPTR_C 655 # define INTPTR_C(x) stdint_intptr_glue3(INT,stdint_intptr_bits,_C)(x) 656 # endif 657 # ifndef UINTPTR_C 658 # define UINTPTR_C(x) stdint_intptr_glue3(UINT,stdint_intptr_bits,_C)(x) 659 # endif 660 typedef stdint_intptr_glue3(uint,stdint_intptr_bits,_t) uintptr_t; 661 typedef stdint_intptr_glue3( int,stdint_intptr_bits,_t) intptr_t; 662 # else 663 /* TODO -- This following is likely wrong for some platforms, and does 664 nothing for the definition of uintptr_t. */ 665 typedef ptrdiff_t intptr_t; 666 # endif 667 # define STDINT_H_UINTPTR_T_DEFINED 668 #endif 669 670 /* 671 * Assumes sig_atomic_t is signed and we have a 2s complement machine. 672 */ 673 674 #ifndef SIG_ATOMIC_MAX 675 # define SIG_ATOMIC_MAX ((((sig_atomic_t) 1) << (sizeof (sig_atomic_t)*CHAR_BIT-1)) - 1) 676 #endif 677 678 #endif 679