OSVR-Core
MSStdIntC.h
Go to the documentation of this file.
1 
14 /* IWYU pragma: private, include <osvr/Util/StdInt.h> */
15 
16 /* ISO C9x 7.18 Integer types <stdint.h>
17  * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
18  *
19  * THIS SOFTWARE IS NOT COPYRIGHTED
20  *
21  * Contributor: Danny Smith <danny_r_smith_2001@yahoo.co.nz>
22  *
23  * This source code is offered for use in the public domain. You may
24  * use, modify or distribute it freely.
25  *
26  * This code is distributed in the hope that it will be useful but
27  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
28  * DISCLAIMED. This includes but is not limited to warranties of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Date: 2000-12-02
32  *
33  * mwb: This was modified in the following ways:
34  *
35  * - make it compatible with Visual C++ 6 (which uses
36  * non-standard keywords and suffixes for 64-bit types)
37  * - some environments need stddef.h included (for wchar stuff?)
38  * - handle the fact that Microsoft's limits.h header defines
39  * SIZE_MAX
40  * - make corrections for SIZE_MAX, INTPTR_MIN, INTPTR_MAX, UINTPTR_MAX,
41  * PTRDIFF_MIN, PTRDIFF_MAX, SIG_ATOMIC_MIN, and SIG_ATOMIC_MAX
42  * to be 64-bit aware.
43  */
44 
45 #ifndef _STDINT_H
46 #define _STDINT_H
47 #ifndef OSVR_DOXYGEN
48 #define __need_wint_t
49 #define __need_wchar_t
50 #include <wchar.h>
51 #include <stddef.h>
52 
53 #if _MSC_VER && (_MSC_VER < 1300)
54 /* using MSVC 6 or earlier - no "long long" type, but might have _int64 type */
55 #define __STDINT_LONGLONG __int64
56 #define __STDINT_LONGLONG_SUFFIX i64
57 #else
58 #define __STDINT_LONGLONG long long
59 #define __STDINT_LONGLONG_SUFFIX LL
60 #endif
61 
62 #if !defined(__MSSTDINT_PASTE)
63 #define __MSSTDINT_PASTE2(x, y) x##y
64 #define __MSSTDINT_PASTE(x, y) __MSSTDINT_PASTE2(x, y)
65 #endif /* __MSSTDINT_PASTE */
66 
67 /* 7.18.1.1 Exact-width integer types */
68 typedef signed char int8_t;
69 typedef unsigned char uint8_t;
70 typedef short int16_t;
71 typedef unsigned short uint16_t;
72 typedef int int32_t;
73 typedef unsigned uint32_t;
74 typedef __STDINT_LONGLONG int64_t;
75 typedef unsigned __STDINT_LONGLONG uint64_t;
76 
77 /* 7.18.1.2 Minimum-width integer types */
78 typedef signed char int_least8_t;
79 typedef unsigned char uint_least8_t;
80 typedef short int_least16_t;
81 typedef unsigned short uint_least16_t;
82 typedef int int_least32_t;
83 typedef unsigned uint_least32_t;
84 typedef __STDINT_LONGLONG int_least64_t;
85 typedef unsigned __STDINT_LONGLONG uint_least64_t;
86 
87 /* 7.18.1.3 Fastest minimum-width integer types
88  * Not actually guaranteed to be fastest for all purposes
89  * Here we use the exact-width types for 8 and 16-bit ints.
90  */
91 typedef char int_fast8_t;
92 typedef unsigned char uint_fast8_t;
93 typedef short int_fast16_t;
94 typedef unsigned short uint_fast16_t;
95 typedef int int_fast32_t;
96 typedef unsigned int uint_fast32_t;
97 typedef __STDINT_LONGLONG int_fast64_t;
98 typedef unsigned __STDINT_LONGLONG uint_fast64_t;
99 
100 /* 7.18.1.4 Integer types capable of holding object pointers */
101 #ifndef _INTPTR_T_DEFINED
102 #define _INTPTR_T_DEFINED
103 #ifdef _WIN64
104 typedef __STDINT_LONGLONG intptr_t
105 #else
106 typedef int intptr_t;
107 #endif /* _WIN64 */
108 #endif /* _INTPTR_T_DEFINED */
109 
110 #ifndef _UINTPTR_T_DEFINED
111 #define _UINTPTR_T_DEFINED
112 #ifdef _WIN64
113  typedef unsigned __STDINT_LONGLONG uintptr_t
114 #else
115 typedef unsigned int uintptr_t;
116 #endif /* _WIN64 */
117 #endif /* _UINTPTR_T_DEFINED */
118 
119  /* 7.18.1.5 Greatest-width integer types */
120  typedef __STDINT_LONGLONG intmax_t;
121 typedef unsigned __STDINT_LONGLONG uintmax_t;
122 
123 /* 7.18.2 Limits of specified-width integer types */
124 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
125 
126 /* 7.18.2.1 Limits of exact-width integer types */
127 #define INT8_MIN (-128)
128 #define INT16_MIN (-32768)
129 #define INT32_MIN (-2147483647 - 1)
130 #define INT64_MIN \
131  (__MSSTDINT_PASTE(-9223372036854775807, __STDINT_LONGLONG_SUFFIX) - 1)
132 
133 #define INT8_MAX 127
134 #define INT16_MAX 32767
135 #define INT32_MAX 2147483647
136 #define INT64_MAX \
137  (__MSSTDINT_PASTE(9223372036854775807, __STDINT_LONGLONG_SUFFIX))
138 
139 #define UINT8_MAX 0xff /* 255U */
140 #define UINT16_MAX 0xffff /* 65535U */
141 #define UINT32_MAX 0xffffffff /* 4294967295U */
142 #define UINT64_MAX \
143  (__MSSTDINT_PASTE(0xffffffffffffffffU, \
144  __STDINT_LONGLONG_SUFFIX)) /* 18446744073709551615ULL */
145 
146 /* 7.18.2.2 Limits of minimum-width integer types */
147 #define INT_LEAST8_MIN INT8_MIN
148 #define INT_LEAST16_MIN INT16_MIN
149 #define INT_LEAST32_MIN INT32_MIN
150 #define INT_LEAST64_MIN INT64_MIN
151 
152 #define INT_LEAST8_MAX INT8_MAX
153 #define INT_LEAST16_MAX INT16_MAX
154 #define INT_LEAST32_MAX INT32_MAX
155 #define INT_LEAST64_MAX INT64_MAX
156 
157 #define UINT_LEAST8_MAX UINT8_MAX
158 #define UINT_LEAST16_MAX UINT16_MAX
159 #define UINT_LEAST32_MAX UINT32_MAX
160 #define UINT_LEAST64_MAX UINT64_MAX
161 
162 /* 7.18.2.3 Limits of fastest minimum-width integer types */
163 #define INT_FAST8_MIN INT8_MIN
164 #define INT_FAST16_MIN INT16_MIN
165 #define INT_FAST32_MIN INT32_MIN
166 #define INT_FAST64_MIN INT64_MIN
167 
168 #define INT_FAST8_MAX INT8_MAX
169 #define INT_FAST16_MAX INT16_MAX
170 #define INT_FAST32_MAX INT32_MAX
171 #define INT_FAST64_MAX INT64_MAX
172 
173 #define UINT_FAST8_MAX UINT8_MAX
174 #define UINT_FAST16_MAX UINT16_MAX
175 #define UINT_FAST32_MAX UINT32_MAX
176 #define UINT_FAST64_MAX UINT64_MAX
177 
178 /* 7.18.2.4 Limits of integer types capable of holding
179  object pointers */
180 #ifdef _WIN64
181 #define INTPTR_MIN INT64_MIN
182 #define INTPTR_MAX INT64_MAX
183 #define UINTPTR_MAX UINT64_MAX
184 #else
185 #define INTPTR_MIN INT32_MIN
186 #define INTPTR_MAX INT32_MAX
187 #define UINTPTR_MAX UINT32_MAX
188 #endif /* _WIN64 */
189 
190 /* 7.18.2.5 Limits of greatest-width integer types */
191 #define INTMAX_MIN INT64_MIN
192 #define INTMAX_MAX INT64_MAX
193 #define UINTMAX_MAX UINT64_MAX
194 
195 /* 7.18.3 Limits of other integer types */
196 #define PTRDIFF_MIN INTPTR_MIN
197 #define PTRDIFF_MAX INTPTR_MAX
198 
199 #define SIG_ATOMIC_MIN INTPTR_MIN
200 #define SIG_ATOMIC_MAX INTPTR_MAX
201 
202 /* we need to check for SIZE_MAX already defined because MS defines it in
203  * limits.h */
204 #ifndef SIZE_MAX
205 #define SIZE_MAX UINTPTR_MAX
206 #endif
207 
208 #ifndef WCHAR_MIN /* also in wchar.h */
209 #define WCHAR_MIN 0
210 #define WCHAR_MAX ((wchar_t)-1) /* UINT16_MAX */
211 #endif
212 
213 /*
214  * wint_t is unsigned short for compatibility with MS runtime
215  */
216 #define WINT_MIN 0
217 #define WINT_MAX ((wint_t)-1) /* UINT16_MAX */
218 
219 #endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */
220 
221 /* 7.18.4 Macros for integer constants */
222 #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
223 
224 /* 7.18.4.1 Macros for minimum-width integer constants
225 
226  Accoding to Douglas Gwyn <gwyn@arl.mil>:
227  "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
228  9899:1999 as initially published, the expansion was required
229  to be an integer constant of precisely matching type, which
230  is impossible to accomplish for the shorter types on most
231  platforms, because C99 provides no standard way to designate
232  an integer constant with width less than that of type int.
233  TC1 changed this to require just an integer constant
234  *expression* with *promoted* type."
235 */
236 
237 #define INT8_C(val) ((int8_t) + (val))
238 #define UINT8_C(val) ((uint8_t) + (val##U))
239 #define INT16_C(val) ((int16_t) + (val))
240 #define UINT16_C(val) ((uint16_t) + (val##U))
241 
242 #define INT32_C(val) val##L
243 #define UINT32_C(val) val##UL
244 #define INT64_C(val) (__MSSTDINT_PASTE(val, __STDINT_LONGLONG_SUFFIX))
245 #define UINT64_C(val) \
246  (__MSSTDINT_PASTE(__MSSTDINT_PASTE(val, U), __STDINT_LONGLONG_SUFFIX))
247 
248 /* 7.18.4.2 Macros for greatest-width integer constants */
249 #define INTMAX_C(val) INT64_C(val)
250 #define UINTMAX_C(val) UINT64_C(val)
251 
252 #endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
253 
254 #undef __MSSTDINT_PASTE
255 #undef __MSSTDINT_PASTE2
256 #endif /* OSVR_DOXYGEN */
257 #endif