]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/stdint.h
xnu-201.14.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / stdint.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000,2001 Apple Computer, Inc. All rights reserved.
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 */
87#define INT8_MIN -128
88#define INT16_MIN -32768
89#define INT32_MIN -2147483648
90#define INT64_MIN -9223372036854775808LL
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 */
135
136#define INTPTR_MIN INT32_MIN
137#define INTPTR_MAX INT32_MAX
138
139#define UINTPTR_MAX UINT32_MAX
140
141/* 7.18.2.5 Limits of greatest-width integer types */
142#define INTMAX_MIN INT64_MIN
143#define INTMAX_MAX INT64_MAX
144
145#define UINTMAX_MAX UINT64_MAX
146
147/* 7.18.3 "Other" */
148#define PTRDIFF_MIN INT32_MIN
149#define PTRDIFF_MAX INT32_MAX
150
151/* We have no sig_atomic_t yet, so no SIG_ATOMIC_{MIN,MAX}.
152 Should end up being {-127,127} or {0,255} ... or bigger.
153 My bet would be on one of {U}INT32_{MIN,MAX}. */
154
155#define SIZE_MAX UINT32_MAX
156
157#define WCHAR_MAX INT32_MAX
158
159/* We have no wint_t yet, so no WINT_{MIN,MAX}.
160 Should end up being {U}INT32_{MIN,MAX}, depending. */
161
162
163#endif /* if C++, then __STDC_LIMIT_MACROS enables the above macros */
164
165/* "C++ implementations should define these macros only when
166 * __STDC_CONSTANT_MACROS is defined before <stdint.h> is included."
167 */
168#if (! defined(__cplusplus)) || defined(__STDC_CONSTANT_MACROS)
169
170/* 7.18.4 Macros for integer constants */
171#define INT8_C(v) ((int8_t)v)
172#define INT16_C(v) ((int16_t)v)
173#define INT32_C(v) (v ## L)
174#define INT64_C(v) (v ## LL)
175
176#define UINT8_C(v) ((uint8_t)v)
177#define UINT16_C(v) ((uint16_t)v)
178#define UINT32_C(v) (v ## UL)
179#define UINT64_C(v) (v ## ULL)
180
181#define INTMAX_C(v) (v ## LL)
182#define UINTMAX_C(v) (v ## ULL)
183
184#endif /* if C++, then __STDC_CONSTANT_MACROS enables the above macros */
185
186#endif /* _STDINT_H_ */