OSDN Git Service

Make <vptype.h> header effectively self-contained.
[mingw/mingw-org-wsl.git] / mingwrt / include / stdint.h
1 /*
2  * stdint.h
3  *
4  * Integer type definitions, as prescribed by ISO-C9x Section 7.18
5  * Based on ISO/IEC SC22/WG14 9899 Committee draft (SC22 N2794)
6  *
7  * $Id$
8  *
9  * Written by Danny Smith <danny_r_smith_2001@yahoo.co.nz>
10  * Copyright (C) 2000-2002, 2004, 2005, 2007, 2009, 2016, 2022,
11  *  MinGW.OSDN Project
12  *
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice, this permission notice, and the following
22  * disclaimer shall be included in all copies or substantial portions of
23  * the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  */
34 #ifndef _STDINT_H
35 #pragma GCC system_header
36
37 /* To support selective definition of just intptr_t or uintptr_t,
38  * we defer definition of the normal multiple inclusion guard macro,
39  * until we've determined that neither selection is active.
40  */
41 #if ! defined __need_intptr_t && ! defined __need_uintptr_t
42 #define _STDINT_H
43
44 /* All MinGW system headers are expected to include <_mingw.h>;
45  * ensure that we have done so.
46  */
47 #include <_mingw.h>
48
49 /* We need to duplicate the definitions of wint_t and wchar_t, as
50  * they are defined in <stddef.h>; get them, by selective inclusion
51  * from that header itself.
52  */
53 #define __need_wint_t
54 #define __need_wchar_t
55 #include <stddef.h>
56
57 /* 7.18.1.1  Exact-width integer types.
58  */
59 typedef signed char             int8_t;
60 typedef unsigned char           uint8_t;
61 typedef short                   int16_t;
62 typedef unsigned short          uint16_t;
63 typedef int                     int32_t;
64 typedef unsigned                uint32_t;
65 typedef long long               int64_t;
66 typedef unsigned long long      uint64_t;
67
68 /* 7.18.1.2  Minimum-width integer types.
69  */
70 typedef signed char             int_least8_t;
71 typedef unsigned char           uint_least8_t;
72 typedef short                   int_least16_t;
73 typedef unsigned short          uint_least16_t;
74 typedef int                     int_least32_t;
75 typedef unsigned                uint_least32_t;
76 typedef long long               int_least64_t;
77 typedef unsigned long long      uint_least64_t;
78
79 /*  7.18.1.3  Fastest minimum-width integer types
80  *  Not actually guaranteed to be fastest for all purposes
81  *  Here we use the exact-width types for 8 and 16-bit ints.
82  */
83 typedef signed char             int_fast8_t;
84 typedef unsigned char           uint_fast8_t;
85 typedef short                   int_fast16_t;
86 typedef unsigned short          uint_fast16_t;
87 typedef int                     int_fast32_t;
88 typedef unsigned  int           uint_fast32_t;
89 typedef long long               int_fast64_t;
90 typedef unsigned long long      uint_fast64_t;
91
92 /* We actually DO need both selections, which had to be omitted
93  * to get us into this conditional block; force them!
94  */
95 #define __need_intptr_t
96 #define __need_uintptr_t
97
98 #endif  /* !__need_intptr_t && !__need_uintptr_t */
99
100 /* 7.18.1.4  Integer types capable of holding object pointers.
101  */
102 #if defined __need_intptr_t && ! defined __intptr_t
103 #define __intptr_t __intptr_t
104 #ifdef _WIN64
105  typedef __int64 __intptr_t;
106 #else
107  typedef int __intptr_t;
108 #endif
109 typedef __intptr_t intptr_t;
110
111 #endif  /* __need_intptr_t */
112 #undef __need_intptr_t
113
114 #if defined __need_uintptr_t && ! defined __uintptr_t
115 #define __uintptr_t __uintptr_t
116 #ifdef _WIN64
117  typedef unsigned __int64 __uintptr_t;
118 #else
119  typedef unsigned int __uintptr_t;
120 #endif
121 typedef __uintptr_t uintptr_t;
122
123 #endif  /* __need_uintptr_t */
124 #undef __need_uintptr_t
125
126 #ifdef  _STDINT_H
127 /* 7.18.1.5  Greatest-width integer types.
128  */
129 typedef long long  intmax_t;
130 typedef unsigned long long uintmax_t;
131
132 /* 7.18.2  Limits of specified-width integer types.
133  * (always defined in C, but C++ needs __STDC_LIMIT_MACROS)
134  */
135 #if ! defined __cplusplus || defined __STDC_LIMIT_MACROS
136
137 /* 7.18.2.1  Limits of exact-width integer types.
138  */
139 #define INT8_MIN                (-128)
140 #define INT16_MIN               (-32768)
141 #define INT32_MIN               (-2147483647 - 1)
142 #define INT64_MIN               (-9223372036854775807LL - 1)
143
144 #define INT8_MAX                127
145 #define INT16_MAX               32767
146 #define INT32_MAX               2147483647
147 #define INT64_MAX               9223372036854775807LL
148
149 #define UINT8_MAX               0xffU                   /* 255U */
150 #define UINT16_MAX              0xffffU                 /* 65535U */
151 #define UINT32_MAX              0xffffffffUL            /* 4294967295U */
152 #define UINT64_MAX              0xffffffffffffffffULL   /* 18446744073709551615ULL */
153
154 /* 7.18.2.2  Limits of minimum-width integer types.
155  */
156 #define INT_LEAST8_MIN          INT8_MIN
157 #define INT_LEAST16_MIN         INT16_MIN
158 #define INT_LEAST32_MIN         INT32_MIN
159 #define INT_LEAST64_MIN         INT64_MIN
160
161 #define INT_LEAST8_MAX          INT8_MAX
162 #define INT_LEAST16_MAX         INT16_MAX
163 #define INT_LEAST32_MAX         INT32_MAX
164 #define INT_LEAST64_MAX         INT64_MAX
165
166 #define UINT_LEAST8_MAX         UINT8_MAX
167 #define UINT_LEAST16_MAX        UINT16_MAX
168 #define UINT_LEAST32_MAX        UINT32_MAX
169 #define UINT_LEAST64_MAX        UINT64_MAX
170
171 /* 7.18.2.3  Limits of fastest minimum-width integer types.
172  */
173 #define INT_FAST8_MIN           INT8_MIN
174 #define INT_FAST16_MIN          INT16_MIN
175 #define INT_FAST32_MIN          INT32_MIN
176 #define INT_FAST64_MIN          INT64_MIN
177
178 #define INT_FAST8_MAX           INT8_MAX
179 #define INT_FAST16_MAX          INT16_MAX
180 #define INT_FAST32_MAX          INT32_MAX
181 #define INT_FAST64_MAX          INT64_MAX
182
183 #define UINT_FAST8_MAX          UINT8_MAX
184 #define UINT_FAST16_MAX         UINT16_MAX
185 #define UINT_FAST32_MAX         UINT32_MAX
186 #define UINT_FAST64_MAX         UINT64_MAX
187
188 /* 7.18.2.4  Limits of integer types capable of holding object pointers.
189  */
190 #ifdef _WIN64
191 # define INTPTR_MIN             INT64_MIN
192 # define INTPTR_MAX             INT64_MAX
193 # define UINTPTR_MAX            UINT64_MAX
194 #else
195 # define INTPTR_MIN             INT32_MIN
196 # define INTPTR_MAX             INT32_MAX
197 # define UINTPTR_MAX            UINT32_MAX
198 #endif
199
200 /* 7.18.2.5  Limits of greatest-width integer types.
201  */
202 #define INTMAX_MIN              INT64_MIN
203 #define INTMAX_MAX              INT64_MAX
204 #define UINTMAX_MAX             UINT64_MAX
205
206 /* 7.18.3  Limits of other integer types.
207  */
208 #define PTRDIFF_MIN             INTPTR_MIN
209 #define PTRDIFF_MAX             INTPTR_MAX
210
211 #define SIG_ATOMIC_MIN          INTPTR_MIN
212 #define SIG_ATOMIC_MAX          INTPTR_MAX
213
214 #define SIZE_MAX                UINTPTR_MAX
215
216 /* The following pair are also defined in <wchar.h>, but leave them
217  * unguarded, so that the compiler may check for consistency.
218  */
219 #define WCHAR_MIN               0
220 #define WCHAR_MAX               0xffff /* UINT16_MAX */
221
222 /* wint_t is unsigned short for compatibility with MS runtime
223  */
224 #define WINT_MIN                0
225 #define WINT_MAX                0xffff /* UINT16_MAX */
226
227 #endif  /* !__cplusplus || __STDC_LIMIT_MACROS */
228
229 /* 7.18.4  Macros for integer constants.
230  * (always defined in C, but C++ needs __STDC_CONSTANT_MACROS)
231  */
232 #if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
233
234 /* 7.18.4.1  Macros for minimum-width integer constants
235  *
236  * According to Douglas Gwyn <gwyn@arl.mil>:
237  *  "This spec was changed in ISO/IEC 9899:1999 TC1; in ISO/IEC
238  *  9899:1999 as initially published, the expansion was required
239  *  to be an integer constant of precisely matching type, which
240  *  is impossible to accomplish for the shorter types on most
241  *  platforms, because C99 provides no standard way to designate
242  *  an integer constant with width less than that of type int.
243  *  TC1 changed this to require just an integer constant
244  *  EXPRESSION with PROMOTED type".
245  */
246 #define INT8_C(val)             val
247 #define UINT8_C(val)            val
248 #define INT16_C(val)            val
249 #define UINT16_C(val)           val
250
251 #define INT32_C(val)            val
252 #define UINT32_C(val)           val##U
253 #define INT64_C(val)            val##LL
254 #define UINT64_C(val)           val##ULL
255
256 /* 7.18.4.2  Macros for greatest-width integer constants.
257  */
258 #define INTMAX_C(val)           INT64_C(val)
259 #define UINTMAX_C(val)          UINT64_C(val)
260
261 #endif  /* !__cplusplus || __STDC_CONSTANT_MACROS */
262 #endif  /* _STDINT_H */
263
264 #endif  /* !_STDINT_H: $RCSfile$: end of file */