OSDN Git Service

a0d7da947a8cfc1cfe01aa9ac9d45563c76f67f9
[uclinux-h8/uClibc.git] / include / stdint.h
1 /* Copyright (C) 1997,1998,1999,2000,2001,2006 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18
19 /*
20  *      ISO C99: 7.18 Integer types <stdint.h>
21  */
22
23 #ifndef _STDINT_H
24 #define _STDINT_H       1
25
26 #include <features.h>
27 #ifdef __UCLIBC_HAS_WCHAR__
28 #include <bits/wchar.h>
29 #endif /* __UCLIBC_HAS_WCHAR__ */
30 #include <bits/wordsize.h>
31
32 /* Exact integral types.  */
33
34 /* Signed.  */
35
36 /* There is some amount of overlap with <sys/types.h> as known by inet code */
37 #ifndef __int8_t_defined
38 # define __int8_t_defined
39 typedef signed char             int8_t;
40 typedef short int               int16_t;
41 typedef int                     int32_t;
42 # if __WORDSIZE == 64
43 typedef long int                int64_t;
44 # else
45 __extension__
46 typedef long long int           int64_t;
47 # endif
48 #endif
49
50 /* Unsigned.  */
51 typedef unsigned char           uint8_t;
52 typedef unsigned short int      uint16_t;
53 #ifndef __uint32_t_defined
54 typedef unsigned int            uint32_t;
55 # define __uint32_t_defined
56 #endif
57 #if __WORDSIZE == 64
58 typedef unsigned long int       uint64_t;
59 #else
60 __extension__
61 typedef unsigned long long int  uint64_t;
62 #endif
63
64
65 /* Small types.  */
66
67 /* Signed.  */
68 typedef signed char             int_least8_t;
69 typedef short int               int_least16_t;
70 typedef int                     int_least32_t;
71 #if __WORDSIZE == 64
72 typedef long int                int_least64_t;
73 #else
74 __extension__
75 typedef long long int           int_least64_t;
76 #endif
77
78 /* Unsigned.  */
79 typedef unsigned char           uint_least8_t;
80 typedef unsigned short int      uint_least16_t;
81 typedef unsigned int            uint_least32_t;
82 #if __WORDSIZE == 64
83 typedef unsigned long int       uint_least64_t;
84 #else
85 __extension__
86 typedef unsigned long long int  uint_least64_t;
87 #endif
88
89
90 /* Fast types.  */
91
92 /* Signed.  */
93 typedef signed char             int_fast8_t;
94 #if __WORDSIZE == 64
95 typedef long int                int_fast16_t;
96 typedef long int                int_fast32_t;
97 typedef long int                int_fast64_t;
98 #else
99 typedef int                     int_fast16_t;
100 typedef int                     int_fast32_t;
101 __extension__
102 typedef long long int           int_fast64_t;
103 #endif
104
105 /* Unsigned.  */
106 typedef unsigned char           uint_fast8_t;
107 #if __WORDSIZE == 64
108 typedef unsigned long int       uint_fast16_t;
109 typedef unsigned long int       uint_fast32_t;
110 typedef unsigned long int       uint_fast64_t;
111 #else
112 typedef unsigned int            uint_fast16_t;
113 typedef unsigned int            uint_fast32_t;
114 __extension__
115 typedef unsigned long long int  uint_fast64_t;
116 #endif
117
118
119 /* Types for `void *' pointers.  */
120 #if __WORDSIZE == 64
121 # ifndef __intptr_t_defined
122 typedef long int                intptr_t;
123 #  define __intptr_t_defined
124 # endif
125 typedef unsigned long int       uintptr_t;
126 #else
127 # ifndef __intptr_t_defined
128 typedef int                     intptr_t;
129 #  define __intptr_t_defined
130 # endif
131 typedef unsigned int            uintptr_t;
132 #endif
133
134
135 /* Largest integral types.  */
136 #if __WORDSIZE == 64
137 typedef long int                intmax_t;
138 typedef unsigned long int       uintmax_t;
139 #else
140 __extension__
141 typedef long long int           intmax_t;
142 __extension__
143 typedef unsigned long long int  uintmax_t;
144 #endif
145
146
147 /* The ISO C99 standard specifies that in C++ implementations these
148    macros should only be defined if explicitly requested.  */
149 #if !defined __cplusplus || defined __STDC_LIMIT_MACROS
150
151 # if __WORDSIZE == 64
152 #  define __INT64_C(c)  c ## L
153 #  define __UINT64_C(c) c ## UL
154 # else
155 #  define __INT64_C(c)  c ## LL
156 #  define __UINT64_C(c) c ## ULL
157 # endif
158
159 /* Limits of integral types.  */
160
161 /* Minimum of signed integral types.  */
162 # define INT8_MIN               (-128)
163 # define INT16_MIN              (-32767-1)
164 # define INT32_MIN              (-2147483647-1)
165 # define INT64_MIN              (-__INT64_C(9223372036854775807)-1)
166 /* Maximum of signed integral types.  */
167 # define INT8_MAX               (127)
168 # define INT16_MAX              (32767)
169 # define INT32_MAX              (2147483647)
170 # define INT64_MAX              (__INT64_C(9223372036854775807))
171
172 /* Maximum of unsigned integral types.  */
173 # define UINT8_MAX              (255)
174 # define UINT16_MAX             (65535)
175 # define UINT32_MAX             (4294967295U)
176 # define UINT64_MAX             (__UINT64_C(18446744073709551615))
177
178
179 /* Minimum of signed integral types having a minimum size.  */
180 # define INT_LEAST8_MIN         (-128)
181 # define INT_LEAST16_MIN        (-32767-1)
182 # define INT_LEAST32_MIN        (-2147483647-1)
183 # define INT_LEAST64_MIN        (-__INT64_C(9223372036854775807)-1)
184 /* Maximum of signed integral types having a minimum size.  */
185 # define INT_LEAST8_MAX         (127)
186 # define INT_LEAST16_MAX        (32767)
187 # define INT_LEAST32_MAX        (2147483647)
188 # define INT_LEAST64_MAX        (__INT64_C(9223372036854775807))
189
190 /* Maximum of unsigned integral types having a minimum size.  */
191 # define UINT_LEAST8_MAX        (255)
192 # define UINT_LEAST16_MAX       (65535)
193 # define UINT_LEAST32_MAX       (4294967295U)
194 # define UINT_LEAST64_MAX       (__UINT64_C(18446744073709551615))
195
196
197 /* Minimum of fast signed integral types having a minimum size.  */
198 # define INT_FAST8_MIN          (-128)
199 # if __WORDSIZE == 64
200 #  define INT_FAST16_MIN        (-9223372036854775807L-1)
201 #  define INT_FAST32_MIN        (-9223372036854775807L-1)
202 # else
203 #  define INT_FAST16_MIN        (-2147483647-1)
204 #  define INT_FAST32_MIN        (-2147483647-1)
205 # endif
206 # define INT_FAST64_MIN         (-__INT64_C(9223372036854775807)-1)
207 /* Maximum of fast signed integral types having a minimum size.  */
208 # define INT_FAST8_MAX          (127)
209 # if __WORDSIZE == 64
210 #  define INT_FAST16_MAX        (9223372036854775807L)
211 #  define INT_FAST32_MAX        (9223372036854775807L)
212 # else
213 #  define INT_FAST16_MAX        (2147483647)
214 #  define INT_FAST32_MAX        (2147483647)
215 # endif
216 # define INT_FAST64_MAX         (__INT64_C(9223372036854775807))
217
218 /* Maximum of fast unsigned integral types having a minimum size.  */
219 # define UINT_FAST8_MAX         (255)
220 # if __WORDSIZE == 64
221 #  define UINT_FAST16_MAX       (18446744073709551615UL)
222 #  define UINT_FAST32_MAX       (18446744073709551615UL)
223 # else
224 #  define UINT_FAST16_MAX       (4294967295U)
225 #  define UINT_FAST32_MAX       (4294967295U)
226 # endif
227 # define UINT_FAST64_MAX        (__UINT64_C(18446744073709551615))
228
229
230 /* Values to test for integral types holding `void *' pointer.  */
231 # if __WORDSIZE == 64
232 #  define INTPTR_MIN            (-9223372036854775807L-1)
233 #  define INTPTR_MAX            (9223372036854775807L)
234 #  define UINTPTR_MAX           (18446744073709551615UL)
235 # else
236 #  define INTPTR_MIN            (-2147483647-1)
237 #  define INTPTR_MAX            (2147483647)
238 #  define UINTPTR_MAX           (4294967295U)
239 # endif
240
241
242 #if !defined(__H8300H__) && !defined(__H8300S__)
243 /* Minimum for largest signed integral type.  */
244 # define INTMAX_MIN             (-__INT64_C(9223372036854775807)-1)
245 /* Maximum for largest signed integral type.  */
246 # define INTMAX_MAX             (__INT64_C(9223372036854775807))
247
248 /* Maximum for largest unsigned integral type.  */
249 # define UINTMAX_MAX            (__UINT64_C(18446744073709551615))
250 #else
251 /* Minimum for largest signed integral type.  */
252 # define INTMAX_MIN             (-LONG_LONG_MAX-1)
253 /* Maximum for largest signed integral type.  */
254 # define INTMAX_MAX             (LONG_LONG_MAX)
255
256 /* Maximum for largest unsigned integral type.  */
257 # define UINTMAX_MAX            (LONG_LONG_MAX<<1+1)
258 #endif
259
260 /* Limits of other integer types.  */
261
262 /* Limits of `ptrdiff_t' type.  */
263 # if __WORDSIZE == 64
264 #  define PTRDIFF_MIN           (-9223372036854775807L-1)
265 #  define PTRDIFF_MAX           (9223372036854775807L)
266 # else
267 #  define PTRDIFF_MIN           (-2147483647-1)
268 #  define PTRDIFF_MAX           (2147483647)
269 # endif
270
271 /* Limits of `sig_atomic_t'.  */
272 # define SIG_ATOMIC_MIN         (-2147483647-1)
273 # define SIG_ATOMIC_MAX         (2147483647)
274
275 /* Limit of `size_t' type.  */
276 # if __WORDSIZE == 64
277 #  define SIZE_MAX              (18446744073709551615UL)
278 # else
279 #  define SIZE_MAX              (4294967295U)
280 # endif
281
282 #ifdef __UCLIBC_HAS_WCHAR__
283 /* Limits of `wchar_t'.  */
284 # ifndef WCHAR_MIN
285 /* These constants might also be defined in <wchar.h>.  */
286 #  define WCHAR_MIN             __WCHAR_MIN
287 #  define WCHAR_MAX             __WCHAR_MAX
288 # endif
289
290 /* Limits of `wint_t'.  */
291 # define WINT_MIN               (0u)
292 # define WINT_MAX               (4294967295u)
293 #endif /* __UCLIBC_HAS_WCHAR__ */
294
295 #endif  /* C++ && limit macros */
296
297
298 /* The ISO C99 standard specifies that in C++ implementations these
299    should only be defined if explicitly requested.  */
300 #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS
301
302 /* Signed.  */
303 # define INT8_C(c)      c
304 # define INT16_C(c)     c
305 # define INT32_C(c)     c
306 # if __WORDSIZE == 64
307 #  define INT64_C(c)    c ## L
308 # else
309 #  define INT64_C(c)    c ## LL
310 # endif
311
312 /* Unsigned.  */
313 # define UINT8_C(c)     c
314 # define UINT16_C(c)    c
315 # define UINT32_C(c)    c ## U
316 # if __WORDSIZE == 64
317 #  define UINT64_C(c)   c ## UL
318 # else
319 #  define UINT64_C(c)   c ## ULL
320 # endif
321
322 /* Maximal type.  */
323 # if __WORDSIZE == 64
324 #  define INTMAX_C(c)   c ## L
325 #  define UINTMAX_C(c)  c ## UL
326 # else
327 #  define INTMAX_C(c)   c ## LL
328 #  define UINTMAX_C(c)  c ## ULL
329 # endif
330
331 #endif  /* C++ && constant macros */
332
333 #endif /* stdint.h */