OSDN Git Service

upgrade to 3.6.2
[jnethack/source.git] / include / integer.h
1 /* NetHack 3.6  integer.h       $NHDT-Date: 1551901047 2019/03/06 19:37:27 $  $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.7 $ */
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 and 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     && !defined(HAS_STDINT_H)
44 /* The compiler claims to conform to C99. Use stdint.h */
45 #define HAS_STDINT_H
46 #endif
47 #if defined(__GNUC__) && defined(__INT64_MAX__) && !defined(HAS_STDINT_H)
48 #define HAS_STDINT_H
49 #endif
50
51 #endif /*?__DECC*/
52
53 #ifdef HAS_STDINT_H
54 #include <stdint.h>
55 #define SKIP_STDINT_WORKAROUND
56 #else /*!stdint*/
57 #ifdef HAS_INTTYPES_H
58 #include <inttypes.h>
59 #define SKIP_STDINT_WORKAROUND
60 #endif
61 #endif /*?stdint*/
62
63 #ifndef SKIP_STDINT_WORKAROUND /* !C99 */
64 /*
65  * STDINT_WORKAROUND section begins here
66  */
67 typedef unsigned char uint8_t;
68 typedef short int16_t;
69 typedef unsigned short uint16_t;
70
71 #if defined(__WATCOMC__) && !defined(__386__)
72 /* Open Watcom providing a 16 bit build for MS-DOS or OS/2 */
73 /* int is 16 bits; use long for 32 bits */
74 typedef long int int32_t;
75 typedef unsigned long int uint32_t;
76 #else
77 /* Otherwise, assume either a 32- or 64-bit compiler */
78 /* long may be 64 bits; use int for 32 bits */
79 typedef int int32_t;
80 typedef unsigned int uint32_t;
81 #endif
82
83 /* The only place where nethack cares about 64-bit integers is in the
84    Isaac64 random number generator.  If your environment can't support
85    64-bit integers, you should comment out USE_ISAAC64 in config.h so
86    that the previous RNG gets used instead.  Then this file will be
87    inhibited and it won't matter what the int64_t and uint64_t lines are. */
88 typedef long long int int64_t;
89 typedef unsigned long long int uint64_t;
90
91 #endif /* !C99 */
92
93 /* Provide uint8, int16, uint16, int32, uint32, int64 and uint64 */
94 typedef uint8_t uint8;
95 typedef int16_t int16;
96 typedef uint16_t uint16;
97 typedef int32_t int32;
98 typedef uint32_t uint32;
99 typedef int64_t int64;
100 typedef uint64_t uint64;
101
102 #endif /* INTEGER_H */