VirtualBox

source: vbox/trunk/include/iprt/stdint.h@ 100725

Last change on this file since 100725 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1/** @file
2 * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
3 */
4
5/*
6 * Copyright (C) 2009-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_stdint_h
37#define IPRT_INCLUDED_stdint_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43
44
45/*
46 * Use the stdint.h on systems that have one.
47 */
48#if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
49 && !(defined(RT_OS_FREEBSD) && defined(_KERNEL)) \
50 && !(defined(RT_OS_NETBSD) && defined(_KERNEL)) \
51 && RT_MSC_PREREQ_EX(RT_MSC_VER_VS2010, 1 /*non-msc*/) \
52 && !defined(__IBMC__) \
53 && !defined(__IBMCPP__) \
54 && !defined(IPRT_NO_CRT) \
55 && !defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
56 && !defined(DOXYGEN_RUNNING)
57
58# ifndef __STDC_CONSTANT_MACROS
59# define __STDC_CONSTANT_MACROS
60# endif
61# ifndef __STDC_LIMIT_MACROS
62# define __STDC_LIMIT_MACROS
63# endif
64# ifdef _MSC_VER
65# pragma warning(push)
66# pragma warning(disable:4668)
67# endif
68# include <stdint.h>
69# ifdef _MSC_VER
70# pragma warning(pop)
71# endif
72
73# if defined(RT_OS_DARWIN) && defined(KERNEL) && defined(RT_ARCH_AMD64)
74 /*
75 * Kludge to fix the incorrect 32-bit constant macros in
76 * Kernel.framework/Headers/stdin.h. uint32_t and int32_t are
77 * int not long as these macros use, which is significant when
78 * targeting AMD64. (10a222)
79 */
80# undef INT32_C
81# define INT32_C(Value) (Value)
82# undef UINT32_C
83# define UINT32_C(Value) (Value ## U)
84# endif /* 64-bit darwin kludge. */
85
86#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
87
88# ifndef __STDC_CONSTANT_MACROS
89# define __STDC_CONSTANT_MACROS
90# endif
91# ifndef __STDC_LIMIT_MACROS
92# define __STDC_LIMIT_MACROS
93# endif
94# include <sys/stdint.h>
95
96#elif defined(RT_OS_NETBSD) && defined(_KERNEL)
97
98# ifndef __STDC_CONSTANT_MACROS
99# define __STDC_CONSTANT_MACROS
100# endif
101# ifndef __STDC_LIMIT_MACROS
102# define __STDC_LIMIT_MACROS
103# endif
104# include <sys/stdint.h>
105
106#else /* No system stdint.h */
107
108/*
109 * Define the types we use.
110 * The linux kernel defines all these in linux/types.h, so skip it.
111 */
112# if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
113 || defined(IPRT_NO_CRT) \
114 || defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
115 || defined(DOXGEN_RUNNING)
116
117 /* Simplify the [u]int64_t type detection mess. */
118# undef IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
119# ifdef __IBMCPP__
120# if __IBMCPP__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
121# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
122# endif
123# endif
124# ifdef __IBMC__
125# if __IBMC__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
126# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
127# endif
128# endif
129
130 /* x-bit types */
131# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) \
132 || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64) \
133 || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
134# if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
135typedef signed char int8_t;
136# endif
137# if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
138typedef unsigned char uint8_t;
139# endif
140# if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
141typedef signed short int16_t;
142# endif
143# if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
144typedef unsigned short uint16_t;
145# endif
146# if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
147# if ARCH_BITS != 16
148typedef signed int int32_t;
149# else
150typedef signed long int32_t;
151# endif
152# endif
153# if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
154# if ARCH_BITS != 16
155typedef unsigned int uint32_t;
156# else
157typedef unsigned long uint32_t;
158# endif
159# endif
160# if defined(_MSC_VER)
161# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
162typedef signed _int64 int64_t;
163# endif
164# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
165typedef unsigned _int64 uint64_t;
166# endif
167# elif defined(__WATCOMC__)
168# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
169typedef signed __int64 int64_t;
170# endif
171# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
172typedef unsigned __int64 uint64_t;
173# endif
174# elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
175# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
176typedef struct { uint32_t lo; int32_t hi; } int64_t;
177# endif
178# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
179typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
180# endif
181# else /* Use long long for 64-bit types */
182# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
183typedef signed long long int64_t;
184# endif
185# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
186typedef unsigned long long uint64_t;
187# endif
188# endif
189
190 /* max integer types */
191# if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
192typedef int64_t intmax_t;
193# endif
194# if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
195typedef uint64_t uintmax_t;
196# endif
197
198 /* smallest minimum-width integer types - assumes to be the same as above! */
199typedef int8_t int_least8_t;
200typedef uint8_t uint_least8_t;
201# define INT_LEAST8_MIN INT8_MIN
202# define INT_LEAST8_MAX INT8_MAX
203# define UINT_LEAST8_MAX UINT8_MAX
204typedef int16_t int_least16_t;
205typedef uint16_t uint_least16_t;
206# define INT_LEAST16_MIN INT16_MIN
207# define INT_LEAST16_MAX INT16_MAX
208# define UINT_LEAST16_MAX UINT16_MAX
209typedef int32_t int_least32_t;
210typedef uint32_t uint_least32_t;
211# define INT_LEAST32_MIN INT32_MIN
212# define INT_LEAST32_MAX INT32_MAX
213# define UINT_LEAST32_MAX UINT32_MAX
214typedef int64_t int_least64_t;
215typedef uint64_t uint_least64_t;
216# define INT_LEAST64_MIN INT64_MIN
217# define INT_LEAST64_MAX INT64_MAX
218# define UINT_LEAST64_MAX UINT64_MAX
219
220 /* fastest minimum-width integer types */
221typedef signed char int_fast8_t;
222typedef unsigned char uint_fast8_t;
223# define INT_FAST8_MIN INT8_MIN
224# define INT_FAST8_MAX INT8_MAX
225# define UINT_FAST8_MAX UINT8_MAX
226typedef signed int int_fast16_t;
227typedef unsigned int uint_fast16_t;
228# if ARCH_BITS == 16
229# define INT_FAST16_MIN INT16_MIN
230# define INT_FAST16_MAX INT16_MAX
231# define UINT_FAST16_MAX UINT16_MAX
232# else
233# define INT_FAST16_MIN INT32_MIN
234# define INT_FAST16_MAX INT32_MAX
235# define UINT_FAST16_MAX UINT32_MAX
236# endif
237typedef int32_t int_fast32_t;
238typedef uint32_t uint_fast32_t;
239# define INT_FAST32_MIN INT32_MIN
240# define INT_FAST32_MAX INT32_MAX
241# define UINT_FAST32_MAX UINT32_MAX
242typedef int64_t int_fast64_t;
243typedef uint64_t uint_fast64_t;
244# define INT_FAST64_MIN INT64_MIN
245# define INT_FAST64_MAX INT64_MAX
246# define UINT_FAST64_MAX UINT64_MAX
247
248# else
249# error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
250# endif
251
252# endif /* !linux kernel or stuff */
253
254 /* pointer <-> integer types */
255# if (!defined(_MSC_VER) && !defined(__WATCOMC__)) || defined(DOXYGEN_RUNNING)
256# if ARCH_BITS == 32 \
257 || defined(RT_OS_LINUX) \
258 || defined(RT_OS_FREEBSD)
259# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
260typedef signed long intptr_t;
261# endif
262# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
263typedef unsigned long uintptr_t;
264# endif
265# else
266# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
267typedef int64_t intptr_t;
268# endif
269# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
270typedef uint64_t uintptr_t;
271# endif
272# endif
273# endif /* !_MSC_VER */
274
275#endif /* no system stdint.h */
276
277
278/*
279 * Make sure the [U]INTx_C(c) macros are present.
280 * For In C++ source the system stdint.h may have skipped these if it was
281 * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
282 */
283#if !defined(INT8_C) \
284 || !defined(INT16_C) \
285 || !defined(INT32_C) \
286 || !defined(INT64_C) \
287 || !defined(INTMAX_C) \
288 || !defined(UINT8_C) \
289 || !defined(UINT16_C) \
290 || !defined(UINT32_C) \
291 || !defined(UINT64_C) \
292 || !defined(UINTMAX_C)
293# define INT8_C(Value) (Value)
294# define INT16_C(Value) (Value)
295# define UINT8_C(Value) (Value)
296# define UINT16_C(Value) (Value)
297# if ARCH_BITS != 16
298# define INT32_C(Value) (Value)
299# define UINT32_C(Value) (Value ## U)
300# define INT64_C(Value) (Value ## LL)
301# define UINT64_C(Value) (Value ## ULL)
302# else
303# define INT32_C(Value) (Value ## L)
304# define UINT32_C(Value) (Value ## UL)
305# define INT64_C(Value) (Value ## LL)
306# define UINT64_C(Value) (Value ## ULL)
307# endif
308# define INTMAX_C(Value) INT64_C(Value)
309# define UINTMAX_C(Value) UINT64_C(Value)
310#endif
311
312
313/*
314 * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
315 * For In C++ source the system stdint.h may have skipped these if it was
316 * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
317 */
318#if !defined(INT8_MIN) \
319 || !defined(INT16_MIN) \
320 || !defined(INT32_MIN) \
321 || !defined(INT64_MIN) \
322 || !defined(INT8_MAX) \
323 || !defined(INT16_MAX) \
324 || !defined(INT32_MAX) \
325 || !defined(INT64_MAX) \
326 || !defined(UINT8_MAX) \
327 || !defined(UINT16_MAX) \
328 || !defined(UINT32_MAX) \
329 || !defined(UINT64_MAX)
330# define INT8_MIN (INT8_C(-0x7f) - 1)
331# define INT16_MIN (INT16_C(-0x7fff) - 1)
332# define INT32_MIN (INT32_C(-0x7fffffff) - 1)
333# define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
334# define INT8_MAX INT8_C(0x7f)
335# define INT16_MAX INT16_C(0x7fff)
336# define INT32_MAX INT32_C(0x7fffffff)
337# define INT64_MAX INT64_C(0x7fffffffffffffff)
338# define UINT8_MAX UINT8_C(0xff)
339# define UINT16_MAX UINT16_C(0xffff)
340# define UINT32_MAX UINT32_C(0xffffffff)
341# define UINT64_MAX UINT64_C(0xffffffffffffffff)
342
343# define INTMAX_MIN INT64_MIN
344# define INTMAX_MAX INT64_MAX
345# define UINTMAX_MAX UINT64_MAX
346#endif
347
348#endif /* !IPRT_INCLUDED_stdint_h */
349
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette