]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/stdint.h
xnu-2050.48.11.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / stdint.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
1c79356b
A
3 *
4 * We build on <machine/types.h> rather than <sys/types.h> in order to
5 * minimize the global namespace pollution (i.e., we'd like to define
6 * *only* those identifiers that the C standard mandates should be
7 * defined by <stdint.h>). Using <machine/types.h> means that (at
8 * least as of January 2001) all of the extra macros that do get
9 * #defined by #include'ing <stdint.h> are in the implementor's
10 * namespace ("_[A-Z].*" or "__.*").
11 *
12 * The reason that we do #include the relevant ...types.h instead of
13 * creating several "competing" typedefs is to make header collisions
14 * less likely during the transition to C99.
15 *
16 * Caveat: There are still five extra typedef's defined by doing it
17 * this way: "u_int{8,16,32,64}_t" and "register_t". Might be
18 * fixable via pre- and post- #defines, but probably not worth it.
19 */
20
21#ifndef _STDINT_H_
22#define _STDINT_H_
23
24#include <machine/types.h>
25
26/* from ISO/IEC 988:1999 spec */
27
28/* 7.18.1.1 Exact-width integer types */
29 /* int8_t is defined in <machine/types.h> */
30 /* int16_t is defined in <machine/types.h> */
31 /* int32_t is defined in <machine/types.h> */
32 /* int64_t is defined in <machine/types.h> */
33typedef u_int8_t uint8_t; /* u_int8_t is defined in <machine/types.h> */
34typedef u_int16_t uint16_t; /* u_int16_t is defined in <machine/types.h> */
35typedef u_int32_t uint32_t; /* u_int32_t is defined in <machine/types.h> */
36typedef u_int64_t uint64_t; /* u_int64_t is defined in <machine/types.h> */
37
38
39/* 7.18.1.2 Minumun-width integer types */
40typedef int8_t int_least8_t;
41typedef int16_t int_least16_t;
42typedef int32_t int_least32_t;
43typedef int64_t int_least64_t;
44typedef uint8_t uint_least8_t;
45typedef uint16_t uint_least16_t;
46typedef uint32_t uint_least32_t;
47typedef uint64_t uint_least64_t;
48
49
50/* 7.18.1.3 Fastest-width integer types */
51typedef int8_t int_fast8_t;
52typedef int16_t int_fast16_t;
53typedef int32_t int_fast32_t;
54typedef int64_t int_fast64_t;
55typedef uint8_t uint_fast8_t;
56typedef uint16_t uint_fast16_t;
57typedef uint32_t uint_fast32_t;
58typedef uint64_t uint_fast64_t;
59
60
61/* 7.18.1.4 Integer types capable of hgolding object pointers */
62 /* intptr_t is defined in <machine/types.h> */
63 /* uintptr_t is defined in <machine/types.h> */
64
65
66/* 7.18.1.5 Greatest-width integer types */
67typedef long long intmax_t;
68typedef unsigned long long uintmax_t;
69
70
71/* "C++ implementations should define these macros only when
72 * __STDC_LIMIT_MACROS is defined before <stdint.h> is included."
73 * In other words, if C++, then __STDC_LIMIT_MACROS enables the
74 * macros below. (Note that there also exists a different enabling
75 * macro (__STDC_CONSTANT_MACROS) for the last few, below.)
76 */
77#if (! defined(__cplusplus)) || defined(__STDC_LIMIT_MACROS)
78
79
80/* 7.18.2 Limits of specified-width integer types:
81 * These #defines specify the minimum and maximum limits
82 * of each of the types declared above.
83 */
84
85
86/* 7.18.2.1 Limits of exact-width integer types */
2d21ac55
A
87#define INT8_MIN (-127-1)
88#define INT16_MIN (-32767-1)
89#define INT32_MIN (-2147483647-1)
90#define INT64_MIN (-9223372036854775807LL-1LL)
1c79356b
A
91
92#define INT8_MAX +127
93#define INT16_MAX +32767
94#define INT32_MAX +2147483647
95#define INT64_MAX +9223372036854775807LL
96
97#define UINT8_MAX 255
98#define UINT16_MAX 65535
99#define UINT32_MAX 4294967295U
100#define UINT64_MAX 18446744073709551615ULL
101
102/* 7.18.2.2 Limits of minimum-width integer types */
103#define INT_LEAST8_MIN INT8_MIN
104#define INT_LEAST16_MIN INT16_MIN
105#define INT_LEAST32_MIN INT32_MIN
106#define INT_LEAST64_MIN INT64_MIN
107
108#define INT_LEAST8_MAX INT8_MAX
109#define INT_LEAST16_MAX INT16_MAX
110#define INT_LEAST32_MAX INT32_MAX
111#define INT_LEAST64_MAX INT64_MAX
112
113#define UINT_LEAST8_MAX UINT8_MAX
114#define UINT_LEAST16_MAX UINT16_MAX
115#define UINT_LEAST32_MAX UINT32_MAX
116#define UINT_LEAST64_MAX UINT64_MAX
117
118/* 7.18.2.3 Limits of fastest minimum-width integer types */
119#define INT_FAST8_MIN INT8_MIN
120#define INT_FAST16_MIN INT16_MIN
121#define INT_FAST32_MIN INT32_MIN
122#define INT_FAST64_MIN INT64_MIN
123
124#define INT_FAST8_MAX INT8_MAX
125#define INT_FAST16_MAX INT16_MAX
126#define INT_FAST32_MAX INT32_MAX
127#define INT_FAST64_MAX INT64_MAX
128
129#define UINT_FAST8_MAX UINT8_MAX
130#define UINT_FAST16_MAX UINT16_MAX
131#define UINT_FAST32_MAX UINT32_MAX
132#define UINT_FAST64_MAX UINT64_MAX
133
134/* 7.18.2.4 Limits of integer types capable of holding object pointers */
2d21ac55
A
135#if defined(__LP64__)
136#define INTPTR_MIN INT64_MIN
137#define INTPTR_MAX INT64_MAX
138#define UINTPTR_MAX UINT64_MAX
139#else
1c79356b
A
140#define INTPTR_MIN INT32_MIN
141#define INTPTR_MAX INT32_MAX
1c79356b 142#define UINTPTR_MAX UINT32_MAX
2d21ac55 143#endif
1c79356b
A
144
145/* 7.18.2.5 Limits of greatest-width integer types */
146#define INTMAX_MIN INT64_MIN
147#define INTMAX_MAX INT64_MAX
148
149#define UINTMAX_MAX UINT64_MAX
150
151/* 7.18.3 "Other" */
2d21ac55
A
152#if defined(__LP64__)
153#define PTRDIFF_MIN INT64_MIN
154#define PTRDIFF_MAX INT64_MAX
155#else
1c79356b
A
156#define PTRDIFF_MIN INT32_MIN
157#define PTRDIFF_MAX INT32_MAX
2d21ac55 158#endif
1c79356b
A
159/* We have no sig_atomic_t yet, so no SIG_ATOMIC_{MIN,MAX}.
160 Should end up being {-127,127} or {0,255} ... or bigger.
161 My bet would be on one of {U}INT32_{MIN,MAX}. */
162
163#define SIZE_MAX UINT32_MAX
164
316670eb 165#ifndef WCHAR_MAX
1c79356b 166#define WCHAR_MAX INT32_MAX
316670eb 167#endif
1c79356b
A
168
169/* We have no wint_t yet, so no WINT_{MIN,MAX}.
170 Should end up being {U}INT32_{MIN,MAX}, depending. */
171
172
173#endif /* if C++, then __STDC_LIMIT_MACROS enables the above macros */
174
175/* "C++ implementations should define these macros only when
176 * __STDC_CONSTANT_MACROS is defined before <stdint.h> is included."
177 */
178#if (! defined(__cplusplus)) || defined(__STDC_CONSTANT_MACROS)
179
180/* 7.18.4 Macros for integer constants */
181#define INT8_C(v) ((int8_t)v)
182#define INT16_C(v) ((int16_t)v)
183#define INT32_C(v) (v ## L)
184#define INT64_C(v) (v ## LL)
185
186#define UINT8_C(v) ((uint8_t)v)
187#define UINT16_C(v) ((uint16_t)v)
188#define UINT32_C(v) (v ## UL)
189#define UINT64_C(v) (v ## ULL)
190
191#define INTMAX_C(v) (v ## LL)
192#define UINTMAX_C(v) (v ## ULL)
193
194#endif /* if C++, then __STDC_CONSTANT_MACROS enables the above macros */
195
196#endif /* _STDINT_H_ */