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