Source:NetHack 5.0.0/include/integer.h
Jump to navigation
Jump to search
Below is the full text to integer.h from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/include/integer.h#line12]], for example.
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* NetHack 5.0 integer.h $NHDT-Date: 1720397754 2024/07/08 00:15:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.13 $ */ 2. /* Copyright (c) 2016 by Michael Allison */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. /* integer.h -- provide sized integer types 6. * 7. * We try to sort out a way to provide sized integer types 8. * in here. The strong preference is to try to let a 9. * compiler-supplied header file set up the types. 10. * 11. * If your compiler is C99 conforming and sets a value of 12. * __STDC_VERSION__ >= 199901L, then <stdint.h> is supposed 13. * to be available for inclusion. 14. * 15. * If your compiler doesn't set __STDC_VERSION__ to indicate 16. * full conformance to C99, but does actually supply a suitable 17. * <stdint.h>, you can pass a compiler flag -DHAS_STDINT_H 18. * during build to cause the inclusion of <stdint.h> anyway. 19. * 20. * If <stdint.h> doesn't get included, then the code in the 21. * STDINT_WORKAROUND section of code is not skipped and will 22. * be used to set up the types. 23. * 24. * We acknowledge that some ongoing maintenance may be needed 25. * over time if people send us code updates for making the 26. * determination of whether <stdint.h> is available, or 27. * require adjustments to the base type used for some 28. * compiler/platform combinations. 29. * 30. */ 31. 32. #ifndef INTEGER_H 33. #define INTEGER_H 34. 35. /* DEC C (aka Compaq C for a while, HP C these days) for VMS is 36. classified as a freestanding implementation rather than a hosted one 37. and even though it claims to be C99, it does not provide <stdint.h>. */ 38. #if defined(__DECC) && defined(VMS) && !defined(HAS_STDINT_H) 39. #define HAS_INTTYPES_H 40. #else /*!__DECC*/ 41. 42. #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) 43. #if !defined(HAS_STDINT_H) 44. /* The compiler claims to conform to C99. Use stdint.h */ 45. #define HAS_STDINT_H 46. #endif /* !HAS_STDINT_H */ 47. #if !defined(HAS_INTTYPES_H) 48. /* The compiler claims to conform to C99. Use inttypes.h */ 49. #define HAS_INTTYPES_H 50. #endif /* !HAS_INTTYPES_H */ 51. #if defined(__GNUC__) && defined(__INT64_MAX__) && !defined(HAS_STDINT_H) 52. #define HAS_STDINT_H 53. #endif 54. #endif /* claims to be C99 */ 55. 56. #endif /*?__DECC*/ 57. 58. #ifdef HAS_STDINT_H 59. #include <stdint.h> 60. #define SKIP_STDINT_WORKAROUND 61. #endif 62. #ifdef HAS_INTTYPES_H 63. #include <inttypes.h> 64. #endif /* HAS_INTTYPES_H */ 65. 66. #ifndef SKIP_STDINT_WORKAROUND /* !C99 */ 67. /* 68. * STDINT_WORKAROUND section begins here 69. */ 70. typedef signed char int8_t; 71. typedef unsigned char uint8_t; 72. typedef short int16_t; 73. typedef unsigned short uint16_t; 74. 75. #if defined(__WATCOMC__) && !defined(__386__) 76. /* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */ 77. /* int is 16 bits; use long for 32 bits */ 78. typedef long int int32_t; 79. typedef unsigned long int uint32_t; 80. #else 81. /* Otherwise, assume either a 32- or 64-bit compiler */ 82. /* long may be 64 bits; use int for 32 bits */ 83. typedef int int32_t; 84. typedef unsigned int uint32_t; 85. #endif 86. 87. /* The only place where nethack cares about 64-bit integers is in the 88. Isaac64 random number generator. If your environment can't support 89. 64-bit integers, you should comment out USE_ISAAC64 in config.h so 90. that the previous RNG gets used instead. Then this file will be 91. inhibited and it won't matter what the int64_t and uint64_t lines are. */ 92. 93. #if defined(__cplusplus) 94. #include <stdint.h> 95. #else 96. typedef long long int int64_t; 97. typedef unsigned long long int uint64_t; 98. #endif 99. 100. #endif /* !C99 */ 101. 102. /* Provide int8, uint8, int16, uint16, int32, uint32, int64 and uint64 */ 103. typedef int8_t int8; 104. typedef uint8_t uint8; 105. typedef int16_t int16; 106. typedef uint16_t uint16; 107. typedef int32_t int32; 108. typedef uint32_t uint32; 109. typedef int64_t int64; 110. typedef uint64_t uint64; 111. 112. /* Also provide ushort, uint, ulong */ 113. typedef unsigned short ushort; 114. typedef unsigned int uint; 115. typedef unsigned long ulong; 116. 117. /* for non-negative L, calculate L * 10 + D, avoiding signed overflow; 118. yields -1 if overflow would have happened; 119. assumes compiler will optimize the constants */ 120. #define AppendLongDigit(L,D) \ 121. (((L) < LONG_MAX / 10L \ 122. || ((L) == LONG_MAX / 10L && (D) <= LONG_MAX % 10L)) \ 123. ? (L) * 10L + (D) \ 124. : -1L) 125. 126. /* add a and b, return max long value if overflow would have occurred; 127. assumes that both a and b are non-negative; caller should apply 128. cast(s) to (long) in the arguments if any are needed */ 129. #define nowrap_add(a,b) ((a) <= (LONG_MAX - (b)) ? ((a) + (b)) : LONG_MAX) 130. 131. #endif /* INTEGER_H */