xref: /xnu-11417.140.69/EXTERNAL_HEADERS/stdint.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions  * Copyright (c) 2000-2010 Apple Inc.
3*43a90889SApple OSS Distributions  * All rights reserved.
4*43a90889SApple OSS Distributions  */
5*43a90889SApple OSS Distributions #if (defined(__has_include) && __has_include(<__xnu_libcxx_sentinel.h>) && !defined(XNU_LIBCXX_SDKROOT))
6*43a90889SApple OSS Distributions 
7*43a90889SApple OSS Distributions #if !__has_include_next(<stdint.h>)
8*43a90889SApple OSS Distributions #error Do not build with -nostdinc (use GCC_USE_STANDARD_INCLUDE_SEARCHING=NO)
9*43a90889SApple OSS Distributions #endif /* __has_include_next */
10*43a90889SApple OSS Distributions 
11*43a90889SApple OSS Distributions #include_next <stdint.h>
12*43a90889SApple OSS Distributions 
13*43a90889SApple OSS Distributions #else /* (defined(__has_include) && __has_include(<__xnu_libcxx_sentinel.h>) && !defined(XNU_LIBCXX_SDKROOT)) */
14*43a90889SApple OSS Distributions 
15*43a90889SApple OSS Distributions #ifndef _KERNEL_STDINT_H_
16*43a90889SApple OSS Distributions #define _KERNEL_STDINT_H_
17*43a90889SApple OSS Distributions 
18*43a90889SApple OSS Distributions #ifndef KERNEL
19*43a90889SApple OSS Distributions /* For user-space code that may include this header */
20*43a90889SApple OSS Distributions #include_next <stdint.h>
21*43a90889SApple OSS Distributions #else /* KERNEL */
22*43a90889SApple OSS Distributions 
23*43a90889SApple OSS Distributions #include <machine/types.h>
24*43a90889SApple OSS Distributions 
25*43a90889SApple OSS Distributions #if __LP64__
26*43a90889SApple OSS Distributions #define __WORDSIZE 64
27*43a90889SApple OSS Distributions #else
28*43a90889SApple OSS Distributions #define __WORDSIZE 32
29*43a90889SApple OSS Distributions #endif
30*43a90889SApple OSS Distributions 
31*43a90889SApple OSS Distributions /* from ISO/IEC 988:1999 spec */
32*43a90889SApple OSS Distributions 
33*43a90889SApple OSS Distributions /* 7.18.1.1 Exact-width integer types */
34*43a90889SApple OSS Distributions /* int8_t is defined in <machine/types.h> */
35*43a90889SApple OSS Distributions /* int16_t is defined in <machine/types.h> */
36*43a90889SApple OSS Distributions /* int32_t is defined in <machine/types.h> */
37*43a90889SApple OSS Distributions /* int64_t is defined in <machine/types.h> */
38*43a90889SApple OSS Distributions typedef u_int8_t              uint8_t;   /* u_int8_t is defined in <machine/types.h> */
39*43a90889SApple OSS Distributions typedef u_int16_t            uint16_t;   /* u_int16_t is defined in <machine/types.h> */
40*43a90889SApple OSS Distributions typedef u_int32_t            uint32_t;   /* u_int32_t is defined in <machine/types.h> */
41*43a90889SApple OSS Distributions typedef u_int64_t            uint64_t;   /* u_int64_t is defined in <machine/types.h> */
42*43a90889SApple OSS Distributions 
43*43a90889SApple OSS Distributions 
44*43a90889SApple OSS Distributions /* 7.18.1.2 Minimum-width integer types */
45*43a90889SApple OSS Distributions typedef int8_t           int_least8_t;
46*43a90889SApple OSS Distributions typedef int16_t         int_least16_t;
47*43a90889SApple OSS Distributions typedef int32_t         int_least32_t;
48*43a90889SApple OSS Distributions typedef int64_t         int_least64_t;
49*43a90889SApple OSS Distributions typedef uint8_t         uint_least8_t;
50*43a90889SApple OSS Distributions typedef uint16_t       uint_least16_t;
51*43a90889SApple OSS Distributions typedef uint32_t       uint_least32_t;
52*43a90889SApple OSS Distributions typedef uint64_t       uint_least64_t;
53*43a90889SApple OSS Distributions 
54*43a90889SApple OSS Distributions 
55*43a90889SApple OSS Distributions /* 7.18.1.3 Fastest-width integer types */
56*43a90889SApple OSS Distributions typedef int8_t            int_fast8_t;
57*43a90889SApple OSS Distributions typedef int16_t          int_fast16_t;
58*43a90889SApple OSS Distributions typedef int32_t          int_fast32_t;
59*43a90889SApple OSS Distributions typedef int64_t          int_fast64_t;
60*43a90889SApple OSS Distributions typedef uint8_t          uint_fast8_t;
61*43a90889SApple OSS Distributions typedef uint16_t        uint_fast16_t;
62*43a90889SApple OSS Distributions typedef uint32_t        uint_fast32_t;
63*43a90889SApple OSS Distributions typedef uint64_t        uint_fast64_t;
64*43a90889SApple OSS Distributions 
65*43a90889SApple OSS Distributions 
66*43a90889SApple OSS Distributions /* 7.18.1.4 Integer types capable of holding object pointers */
67*43a90889SApple OSS Distributions /* intptr_t is defined in <machine/types.h> */
68*43a90889SApple OSS Distributions /* uintptr_t is defined in <machine/types.h> */
69*43a90889SApple OSS Distributions 
70*43a90889SApple OSS Distributions 
71*43a90889SApple OSS Distributions /* 7.18.1.5 Greatest-width integer types */
72*43a90889SApple OSS Distributions #ifdef __INTMAX_TYPE__
73*43a90889SApple OSS Distributions typedef __INTMAX_TYPE__ intmax_t;
74*43a90889SApple OSS Distributions #else
75*43a90889SApple OSS Distributions #ifdef __LP64__
76*43a90889SApple OSS Distributions typedef long int intmax_t;
77*43a90889SApple OSS Distributions #else
78*43a90889SApple OSS Distributions typedef long long int intmax_t;
79*43a90889SApple OSS Distributions #endif /* __LP64__ */
80*43a90889SApple OSS Distributions #endif /* __INTMAX_TYPE__ */
81*43a90889SApple OSS Distributions #ifdef __UINTMAX_TYPE__
82*43a90889SApple OSS Distributions typedef __UINTMAX_TYPE__ uintmax_t;
83*43a90889SApple OSS Distributions #else
84*43a90889SApple OSS Distributions #ifdef __LP64__
85*43a90889SApple OSS Distributions typedef long unsigned int uintmax_t;
86*43a90889SApple OSS Distributions #else
87*43a90889SApple OSS Distributions typedef long long unsigned int uintmax_t;
88*43a90889SApple OSS Distributions #endif /* __LP64__ */
89*43a90889SApple OSS Distributions #endif /* __UINTMAX_TYPE__ */
90*43a90889SApple OSS Distributions 
91*43a90889SApple OSS Distributions /* 7.18.4 Macros for integer constants */
92*43a90889SApple OSS Distributions #define INT8_C(v)    (v)
93*43a90889SApple OSS Distributions #define INT16_C(v)   (v)
94*43a90889SApple OSS Distributions #define INT32_C(v)   (v)
95*43a90889SApple OSS Distributions #define INT64_C(v)   (v ## LL)
96*43a90889SApple OSS Distributions 
97*43a90889SApple OSS Distributions #define UINT8_C(v)   (v)
98*43a90889SApple OSS Distributions #define UINT16_C(v)  (v)
99*43a90889SApple OSS Distributions #define UINT32_C(v)  (v ## U)
100*43a90889SApple OSS Distributions #define UINT64_C(v)  (v ## ULL)
101*43a90889SApple OSS Distributions 
102*43a90889SApple OSS Distributions #ifdef __LP64__
103*43a90889SApple OSS Distributions #define INTMAX_C(v)  (v ## L)
104*43a90889SApple OSS Distributions #define UINTMAX_C(v) (v ## UL)
105*43a90889SApple OSS Distributions #else
106*43a90889SApple OSS Distributions #define INTMAX_C(v)  (v ## LL)
107*43a90889SApple OSS Distributions #define UINTMAX_C(v) (v ## ULL)
108*43a90889SApple OSS Distributions #endif
109*43a90889SApple OSS Distributions 
110*43a90889SApple OSS Distributions /* 7.18.2 Limits of specified-width integer types:
111*43a90889SApple OSS Distributions  *   These #defines specify the minimum and maximum limits
112*43a90889SApple OSS Distributions  *   of each of the types declared above.
113*43a90889SApple OSS Distributions  *
114*43a90889SApple OSS Distributions  *   They must have "the same type as would an expression that is an
115*43a90889SApple OSS Distributions  *   object of the corresponding type converted according to the integer
116*43a90889SApple OSS Distributions  *   promotion".
117*43a90889SApple OSS Distributions  */
118*43a90889SApple OSS Distributions 
119*43a90889SApple OSS Distributions 
120*43a90889SApple OSS Distributions /* 7.18.2.1 Limits of exact-width integer types */
121*43a90889SApple OSS Distributions #define INT8_MAX         127
122*43a90889SApple OSS Distributions #define INT16_MAX        32767
123*43a90889SApple OSS Distributions #define INT32_MAX        2147483647
124*43a90889SApple OSS Distributions #define INT64_MAX        9223372036854775807LL
125*43a90889SApple OSS Distributions 
126*43a90889SApple OSS Distributions #define INT8_MIN          -128
127*43a90889SApple OSS Distributions #define INT16_MIN         -32768
128*43a90889SApple OSS Distributions /*
129*43a90889SApple OSS Distributions  *  Note:  the literal "most negative int" cannot be written in C --
130*43a90889SApple OSS Distributions  *  the rules in the standard (section 6.4.4.1 in C99) will give it
131*43a90889SApple OSS Distributions  *  an unsigned type, so INT32_MIN (and the most negative member of
132*43a90889SApple OSS Distributions  *  any larger signed type) must be written via a constant expression.
133*43a90889SApple OSS Distributions  */
134*43a90889SApple OSS Distributions #define INT32_MIN        (-INT32_MAX-1)
135*43a90889SApple OSS Distributions #define INT64_MIN        (-INT64_MAX-1)
136*43a90889SApple OSS Distributions 
137*43a90889SApple OSS Distributions #define UINT8_MAX         255
138*43a90889SApple OSS Distributions #define UINT16_MAX        65535
139*43a90889SApple OSS Distributions #define UINT32_MAX        4294967295U
140*43a90889SApple OSS Distributions #define UINT64_MAX        18446744073709551615ULL
141*43a90889SApple OSS Distributions 
142*43a90889SApple OSS Distributions /* 7.18.2.2 Limits of minimum-width integer types */
143*43a90889SApple OSS Distributions #define INT_LEAST8_MIN    INT8_MIN
144*43a90889SApple OSS Distributions #define INT_LEAST16_MIN   INT16_MIN
145*43a90889SApple OSS Distributions #define INT_LEAST32_MIN   INT32_MIN
146*43a90889SApple OSS Distributions #define INT_LEAST64_MIN   INT64_MIN
147*43a90889SApple OSS Distributions 
148*43a90889SApple OSS Distributions #define INT_LEAST8_MAX    INT8_MAX
149*43a90889SApple OSS Distributions #define INT_LEAST16_MAX   INT16_MAX
150*43a90889SApple OSS Distributions #define INT_LEAST32_MAX   INT32_MAX
151*43a90889SApple OSS Distributions #define INT_LEAST64_MAX   INT64_MAX
152*43a90889SApple OSS Distributions 
153*43a90889SApple OSS Distributions #define UINT_LEAST8_MAX   UINT8_MAX
154*43a90889SApple OSS Distributions #define UINT_LEAST16_MAX  UINT16_MAX
155*43a90889SApple OSS Distributions #define UINT_LEAST32_MAX  UINT32_MAX
156*43a90889SApple OSS Distributions #define UINT_LEAST64_MAX  UINT64_MAX
157*43a90889SApple OSS Distributions 
158*43a90889SApple OSS Distributions /* 7.18.2.3 Limits of fastest minimum-width integer types */
159*43a90889SApple OSS Distributions #define INT_FAST8_MIN     INT8_MIN
160*43a90889SApple OSS Distributions #define INT_FAST16_MIN    INT16_MIN
161*43a90889SApple OSS Distributions #define INT_FAST32_MIN    INT32_MIN
162*43a90889SApple OSS Distributions #define INT_FAST64_MIN    INT64_MIN
163*43a90889SApple OSS Distributions 
164*43a90889SApple OSS Distributions #define INT_FAST8_MAX     INT8_MAX
165*43a90889SApple OSS Distributions #define INT_FAST16_MAX    INT16_MAX
166*43a90889SApple OSS Distributions #define INT_FAST32_MAX    INT32_MAX
167*43a90889SApple OSS Distributions #define INT_FAST64_MAX    INT64_MAX
168*43a90889SApple OSS Distributions 
169*43a90889SApple OSS Distributions #define UINT_FAST8_MAX    UINT8_MAX
170*43a90889SApple OSS Distributions #define UINT_FAST16_MAX   UINT16_MAX
171*43a90889SApple OSS Distributions #define UINT_FAST32_MAX   UINT32_MAX
172*43a90889SApple OSS Distributions #define UINT_FAST64_MAX   UINT64_MAX
173*43a90889SApple OSS Distributions 
174*43a90889SApple OSS Distributions /* 7.18.2.4 Limits of integer types capable of holding object pointers */
175*43a90889SApple OSS Distributions 
176*43a90889SApple OSS Distributions #if __WORDSIZE == 64
177*43a90889SApple OSS Distributions #define INTPTR_MAX        9223372036854775807L
178*43a90889SApple OSS Distributions #else
179*43a90889SApple OSS Distributions #define INTPTR_MAX        2147483647L
180*43a90889SApple OSS Distributions #endif
181*43a90889SApple OSS Distributions #define INTPTR_MIN        (-INTPTR_MAX-1)
182*43a90889SApple OSS Distributions 
183*43a90889SApple OSS Distributions #if __WORDSIZE == 64
184*43a90889SApple OSS Distributions #define UINTPTR_MAX       18446744073709551615UL
185*43a90889SApple OSS Distributions #else
186*43a90889SApple OSS Distributions #define UINTPTR_MAX       4294967295UL
187*43a90889SApple OSS Distributions #endif
188*43a90889SApple OSS Distributions 
189*43a90889SApple OSS Distributions /* 7.18.2.5 Limits of greatest-width integer types */
190*43a90889SApple OSS Distributions #define INTMAX_MAX        INTMAX_C(9223372036854775807)
191*43a90889SApple OSS Distributions #define UINTMAX_MAX       UINTMAX_C(18446744073709551615)
192*43a90889SApple OSS Distributions #define INTMAX_MIN        (-INTMAX_MAX-1)
193*43a90889SApple OSS Distributions 
194*43a90889SApple OSS Distributions /* 7.18.3 "Other" */
195*43a90889SApple OSS Distributions #if __WORDSIZE == 64
196*43a90889SApple OSS Distributions #define PTRDIFF_MIN       INTMAX_MIN
197*43a90889SApple OSS Distributions #define PTRDIFF_MAX       INTMAX_MAX
198*43a90889SApple OSS Distributions #else
199*43a90889SApple OSS Distributions #define PTRDIFF_MIN       INT32_MIN
200*43a90889SApple OSS Distributions #define PTRDIFF_MAX       INT32_MAX
201*43a90889SApple OSS Distributions #endif
202*43a90889SApple OSS Distributions 
203*43a90889SApple OSS Distributions #define SIZE_MAX          UINTPTR_MAX
204*43a90889SApple OSS Distributions 
205*43a90889SApple OSS Distributions #if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
206*43a90889SApple OSS Distributions #define RSIZE_MAX         (SIZE_MAX >> 1)
207*43a90889SApple OSS Distributions #endif
208*43a90889SApple OSS Distributions 
209*43a90889SApple OSS Distributions #ifndef WCHAR_MAX
210*43a90889SApple OSS Distributions #  ifdef __WCHAR_MAX__
211*43a90889SApple OSS Distributions #    define WCHAR_MAX     __WCHAR_MAX__
212*43a90889SApple OSS Distributions #  else
213*43a90889SApple OSS Distributions #    define WCHAR_MAX     0x7fffffff
214*43a90889SApple OSS Distributions #  endif
215*43a90889SApple OSS Distributions #endif
216*43a90889SApple OSS Distributions 
217*43a90889SApple OSS Distributions /* WCHAR_MIN should be 0 if wchar_t is an unsigned type and
218*43a90889SApple OSS Distributions  *  (-WCHAR_MAX-1) if wchar_t is a signed type.  Unfortunately,
219*43a90889SApple OSS Distributions  *  it turns out that -fshort-wchar changes the signedness of
220*43a90889SApple OSS Distributions  *  the type. */
221*43a90889SApple OSS Distributions #ifndef WCHAR_MIN
222*43a90889SApple OSS Distributions #  if WCHAR_MAX == 0xffff
223*43a90889SApple OSS Distributions #    define WCHAR_MIN       0
224*43a90889SApple OSS Distributions #  else
225*43a90889SApple OSS Distributions #    define WCHAR_MIN       (-WCHAR_MAX-1)
226*43a90889SApple OSS Distributions #  endif
227*43a90889SApple OSS Distributions #endif
228*43a90889SApple OSS Distributions 
229*43a90889SApple OSS Distributions #define WINT_MIN          INT32_MIN
230*43a90889SApple OSS Distributions #define WINT_MAX          INT32_MAX
231*43a90889SApple OSS Distributions 
232*43a90889SApple OSS Distributions #define SIG_ATOMIC_MIN    INT32_MIN
233*43a90889SApple OSS Distributions #define SIG_ATOMIC_MAX    INT32_MAX
234*43a90889SApple OSS Distributions 
235*43a90889SApple OSS Distributions #endif /* KERNEL */
236*43a90889SApple OSS Distributions 
237*43a90889SApple OSS Distributions #endif /* _KERNEL_STDINT_H_ */
238*43a90889SApple OSS Distributions 
239*43a90889SApple OSS Distributions #endif
240