aboutsummaryrefslogtreecommitdiff
path: root/ports/winnt/include/stdint.h
blob: 4040c24f0f84e79da40e6de93edc6ee5e2b1d9cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
 * stdint_msvc.h - C99 integer types for older Visual C compilers
 *
 * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project.
 * The contents of 'html/copyright.html' apply.
 *
 * ----------------------------------------------------------------------
 *
 * Fairly straight forward implementation of the C99 standard integer
 * types.
 */

#ifndef __STDINT_INCLUDED
#define __STDINT_INCLUDED

#if !defined(_MSC_VER) || _MSC_VER >= 1800
# error Use only with MSVC6 - MSVC11(VS2012)
#endif

#include <crtdefs.h>
#include <limits.h>

/* ---------------------------------------------------------------------
 * We declare the min/max values, using the MSVC syntax for literals of
 * a given bit width.
 */

#define _VC_SI_LIT(lit,wbit)	(lit ##  i ## wbit)
#define _VC_UI_LIT(lit,wbit)	(lit ## ui ## wbit)

/* ---------------------------------------------------------------------
 * Exact width integer types
 */
typedef	__int8	int8_t;
typedef	__int16	int16_t;
typedef	__int32	int32_t;
typedef	__int64	int64_t;

typedef unsigned __int8  uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;

#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
# define INT8_MIN   _I8_MIN
# define INT8_MAX   _I8_MAX
# define UINT8_MAX  _UI8_MAX
# define INT16_MIN  _I16_MIN
# define INT16_MAX  _I16_MAX
# define UINT16_MAX _UI16_MAX
# define INT32_MIN  _I32_MIN
# define INT32_MAX  _I32_MAX
# define UINT32_MAX _UI32_MAX
# define INT64_MIN  _I64_MIN
# define INT64_MAX  _I64_MAX
# define UINT64_MAX _UI64_MAX
#endif

/* ---------------------------------------------------------------------
 * Least-size integers
 *
 * These are mapped to exact size.
 */
typedef	__int8	int_least8_t;
typedef	__int16	int_least16_t;
typedef	__int32	int_least32_t;
typedef	__int64	int_least64_t;

typedef unsigned  __int8 uint_least8_t;
typedef unsigned __int16 uint_least16_t;
typedef unsigned __int32 uint_least32_t;
typedef unsigned __int64 uint_least64_t;

#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
#define INT_LEAST8_MIN   _I8_MIN
#define INT_LEAST8_MAX	 _I8_MAX
#define UINT_LEAST8_MAX  _UI8_MAX
#define INT_LEAST16_MIN	 _I16_MIN
#define INT_LEAST16_MAX	 _I16_MAX
#define UINT_LEAST16_MAX _UI16_MAX
#define INT_LEAST32_MIN	 _I32_MIN
#define INT_LEAST32_MAX	 _I32_MAX
#define UINT_LEAST32_MAX _UI32_MAX
#define INT_LEAST64_MIN  _I64_MIN
#define INT_LEAST64_MAX	 _I64_MAX
#define UINT_LEAST64_MAX _UI64_MAX
#endif

/* ---------------------------------------------------------------------
 * least-size, fastest integer
 *
 * The 'FAST' types are all 32 bits, except the 64 bit quantity; as the
 * natural register width is 32 bits, quantities of that size are fastest
 * to operate on naturally. (This even holds for the x86_64; MSVC uses
 * the 'llp64' model.
 */
typedef	__int32	int_fast8_t;
typedef	__int32	int_fast16_t;
typedef	__int32	int_fast32_t;
typedef	__int64	int_fast64_t;

typedef unsigned __int32 uint_fast8_t;
typedef unsigned __int32 uint_fast16_t;
typedef unsigned __int32 uint_fast32_t;
typedef unsigned __int64 uint_fast64_t;

#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
#define INT_FAST8_MIN   _I32_MIN
#define INT_FAST8_MAX   _I32_MAX
#define UINT_FAST8_MAX	_UI32_MAX
#define INT_FAST16_MIN  _I32_MIN
#define INT_FAST16_MAX  _I32_MAX
#define UINT_FAST16_MAX	_UI32_MAX
#define INT_FAST32_MIN  _I32_MIN
#define INT_FAST32_MAX  _I32_MAX
#define UINT_FAST32_MAX	_UI32_MAX
#define INT_FAST64_MIN  _I64_MIN
#define INT_FAST64_MAX  _I64_MAX
#define UINT_FAST64_MAX	_UI64_MAX
#endif

/* ---------------------------------------------------------------------
 * The (u)intptr_t, ptrdiff_t and size_t definitions depend on the
 * target: 32bit for x86, and 64bit for x64, aka amd64. Well, we
 * have to bite the bullet.
 */

/* ------------------------------------------------------------------ */
# if defined(_WIN64) || defined(WIN64)
/* ------------------------------------------------------------------ */

# ifndef _INTPTR_T_DEFINED
#  define _INTPTR_T_DEFINED
   typedef __int64 intptr_t;
# endif

# ifndef _UINTPTR_T_DEFINED
#  define _UINTPTR_T_DEFINED
   typedef unsigned __int64 uintptr_t;
# endif

# ifndef _PTRDIFF_T_DEFINED
#  define _PTRDIFF_T_DEFINED
   typedef __int64 ptrdiff_t;
# endif

# if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
#  ifndef INTPTR_MIN
#   define INTPTR_MIN _I64_MIN
#  endif
#  ifndef INTPTR_MAX
#   define INTPTR_MAX _I64_MAX
#  endif
#  ifndef UINTPTR_MAX
#   define UINTPTR_MAX _UI64_MAX
#  endif
#  ifndef PTRDIFF_MIN
#   define PTRDIFF_MIN _I64_MIN
#  endif
#  ifndef PTRDIFF_MAX
#   define PTRDIFF_MAX _I64_MAX
#  endif
# endif

/* ------------------------------------------------------------------ */
#else   /* 32 bit target assumed here! */
/* ------------------------------------------------------------------ */

# ifndef _INTPTR_T_DEFINED
#  define _INTPTR_T_DEFINED
   typedef __int32 intptr_t;
# endif

# ifndef _UINTPTR_T_DEFINED
#  define _UINTPTR_T_DEFINED
   typedef unsigned __int32 uintptr_t;
# endif

# ifndef _PTRDIFF_T_DEFINED
#  define _PTRDIFF_T_DEFINED
   typedef __int64 ptrdiff_t;
# endif

# if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
#  ifndef INTPTR_MIN
#   define INTPTR_MIN _I32_MIN
#  endif
#  ifndef INTPTR_MAX
#   define INTPTR_MAX _I32_MAX
#  endif
#  ifndef UINTPTR_MAX
#   define UINTPTR_MAX _UI32_MAX
#  endif
#  ifndef PTRDIFF_MIN
#   define PTRDIFF_MIN _I32_MIN
#  endif
#  ifndef PTRDIFF_MAX
#   define PTRDIFF_MAX _I32_MAX
#  endif
# endif
#endif /* platform dependent stuff */


/* ---------------------------------------------------------------------
 * max integer is 64-bit integer
 */
typedef __int64	intmax_t;
typedef unsigned __int64 uintmax_t;

#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS)
# define INTMAX_MIN  _I64_MIN
# define INTMAX_MAX  _I64_MAX
# define UINTMAX_MAX _UI64_MAX
#endif

/* ---------------------------------------------------------------------
 * limit for size_t (older MSVC versions lack that one)
 */
#if _MSC_VER <=1200
# if defined(_WIN64) || defined(WIN64)
#  define SIZE_MAX _UI64_MAX
#else
#  define SIZE_MAX _UI32_MAX
# endif
#endif

/* ---------------------------------------------------------------------
 * construct numerical literals with precise size
 */
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS)
# define INT8_C(lit)    _VC_SI_LIT(lit,8)
# define UINT8_C(lit)   _VC_UI_LIT(lit,8)
# define INT16_C(lit)   _VC_SI_LIT(lit,16)
# define UINT16_C(lit)  _VC_UI_LIT(lit,16)
# define INT32_C(lit)   _VC_SI_LIT(lit,32)
# define UINT32_C(lit)  _VC_UI_LIT(lit,32)
# define INT64_C(lit)   _VC_SI_LIT(lit,64)
# define UINT64_C(lit)  _VC_UI_LIT(lit,64)
# define INTMAX_C(lit)  _VC_SI_LIT(lit,64)
# define UINTMAX_C(lit) _VC_UI_LIT(lit,64)
#endif

#endif
/**** EOF ****/