VirtualBox

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

Last change on this file since 107807 was 107249, checked in by vboxsync, 2 months ago

iprt/stdin.h: Another parfait/solaris kludge.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 KB
Line 
1/** @file
2 * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
3 */
4
5/*
6 * Copyright (C) 2009-2024 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 && !defined(__ASSEMBLER__)
58
59# ifndef __STDC_CONSTANT_MACROS
60# define __STDC_CONSTANT_MACROS
61# endif
62# ifndef __STDC_LIMIT_MACROS
63# define __STDC_LIMIT_MACROS
64# endif
65# ifdef _MSC_VER
66# pragma warning(push)
67# pragma warning(disable:4668)
68# endif
69# include <stdint.h>
70# ifdef _MSC_VER
71# pragma warning(pop)
72# endif
73
74# if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_PARFAIT)
75 /* HACK ALERT: Workaround for missing __UINT32_C and friends (clang vs gcc?). */
76# ifndef __UINT8_C
77# define __UINT8_C(c) c
78# endif
79# ifndef __UINT16_C
80# define __UINT16_C(c) c
81# endif
82# ifndef __UINT32_C
83# define __UINT32_C(c) RT_CONCAT(c,U)
84# endif
85# ifndef __UINT64_C
86# define __UINT64_C(c) RT_CONCAT(c,UL)
87# endif
88# ifndef __UINTMAX_C
89# define __UINTMAX_C(c) RT_CONCAT(c,UL)
90# endif
91# ifndef __INT8_C
92# define __INT8_C(c) c
93# endif
94# ifndef __INT16_C
95# define __INT16_C(c) c
96# endif
97# ifndef __INT32_C
98# define __INT32_C(c) c
99# endif
100# ifndef __INT64_C
101# define __INT64_C(c) RT_CONCAT(c,L)
102# endif
103# ifndef __INTMAX_C
104# define __INTMAX_C(c) RT_CONCAT(c,L)
105# endif
106# endif
107
108# if defined(RT_OS_DARWIN) && defined(KERNEL) && defined(RT_ARCH_AMD64)
109 /*
110 * Kludge to fix the incorrect 32-bit constant macros in
111 * Kernel.framework/Headers/stdin.h. uint32_t and int32_t are
112 * int not long as these macros use, which is significant when
113 * targeting AMD64. (10a222)
114 */
115# undef INT32_C
116# define INT32_C(Value) (Value)
117# undef UINT32_C
118# define UINT32_C(Value) (Value ## U)
119# endif /* 64-bit darwin kludge. */
120
121#elif defined(RT_OS_FREEBSD) && defined(_KERNEL) && !defined(__ASSEMBLER__)
122
123# ifndef __STDC_CONSTANT_MACROS
124# define __STDC_CONSTANT_MACROS
125# endif
126# ifndef __STDC_LIMIT_MACROS
127# define __STDC_LIMIT_MACROS
128# endif
129# include <sys/stdint.h>
130
131#elif defined(RT_OS_NETBSD) && defined(_KERNEL) && !defined(__ASSEMBLER__)
132
133# ifndef __STDC_CONSTANT_MACROS
134# define __STDC_CONSTANT_MACROS
135# endif
136# ifndef __STDC_LIMIT_MACROS
137# define __STDC_LIMIT_MACROS
138# endif
139# include <sys/stdint.h>
140
141#else /* No system stdint.h */
142
143/*
144 * Define the types we use.
145 * The linux kernel defines all these in linux/types.h, so skip it.
146 */
147# if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
148 || defined(IPRT_NO_CRT) \
149 || defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
150 || defined(DOXGEN_RUNNING)
151
152 /* Simplify the [u]int64_t type detection mess. */
153# undef IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
154# ifdef __IBMCPP__
155# if __IBMCPP__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
156# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
157# endif
158# endif
159# ifdef __IBMC__
160# if __IBMC__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
161# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
162# endif
163# endif
164
165 /* x-bit types */
166# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) \
167 || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64) \
168 || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
169# ifndef __ASSEMBLER__
170# if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
171typedef signed char int8_t;
172# endif
173# if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
174typedef unsigned char uint8_t;
175# endif
176# if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
177typedef signed short int16_t;
178# endif
179# if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
180typedef unsigned short uint16_t;
181# endif
182# if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
183# if ARCH_BITS != 16
184typedef signed int int32_t;
185# else
186typedef signed long int32_t;
187# endif
188# endif
189# if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
190# if ARCH_BITS != 16
191typedef unsigned int uint32_t;
192# else
193typedef unsigned long uint32_t;
194# endif
195# endif
196# if defined(_MSC_VER)
197# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
198typedef signed _int64 int64_t;
199# endif
200# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
201typedef unsigned _int64 uint64_t;
202# endif
203# elif defined(__WATCOMC__)
204# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
205typedef signed __int64 int64_t;
206# endif
207# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
208typedef unsigned __int64 uint64_t;
209# endif
210# elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
211# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
212typedef struct { uint32_t lo; int32_t hi; } int64_t;
213# endif
214# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
215typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
216# endif
217# else /* Use long long for 64-bit types */
218# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
219typedef signed long long int64_t;
220# endif
221# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
222typedef unsigned long long uint64_t;
223# endif
224# endif
225
226 /* max integer types */
227# if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
228typedef int64_t intmax_t;
229# endif
230# if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
231typedef uint64_t uintmax_t;
232# endif
233# endif /* !__ASSEMBLER__ */
234
235 /* smallest minimum-width integer types - assumes to be the same as above! */
236# ifndef __ASSEMBLER__
237typedef int8_t int_least8_t;
238typedef uint8_t uint_least8_t;
239# endif
240# define INT_LEAST8_MIN INT8_MIN
241# define INT_LEAST8_MAX INT8_MAX
242# define UINT_LEAST8_MAX UINT8_MAX
243# ifndef __ASSEMBLER__
244typedef int16_t int_least16_t;
245typedef uint16_t uint_least16_t;
246# endif
247# define INT_LEAST16_MIN INT16_MIN
248# define INT_LEAST16_MAX INT16_MAX
249# define UINT_LEAST16_MAX UINT16_MAX
250# ifndef __ASSEMBLER__
251typedef int32_t int_least32_t;
252typedef uint32_t uint_least32_t;
253# endif
254# define INT_LEAST32_MIN INT32_MIN
255# define INT_LEAST32_MAX INT32_MAX
256# define UINT_LEAST32_MAX UINT32_MAX
257# ifndef __ASSEMBLER__
258typedef int64_t int_least64_t;
259typedef uint64_t uint_least64_t;
260# endif
261# define INT_LEAST64_MIN INT64_MIN
262# define INT_LEAST64_MAX INT64_MAX
263# define UINT_LEAST64_MAX UINT64_MAX
264
265 /* fastest minimum-width integer types */
266# ifndef __ASSEMBLER__
267typedef signed char int_fast8_t;
268typedef unsigned char uint_fast8_t;
269# endif
270# define INT_FAST8_MIN INT8_MIN
271# define INT_FAST8_MAX INT8_MAX
272# define UINT_FAST8_MAX UINT8_MAX
273# ifndef __ASSEMBLER__
274typedef signed int int_fast16_t;
275typedef unsigned int uint_fast16_t;
276# endif
277# if ARCH_BITS == 16
278# define INT_FAST16_MIN INT16_MIN
279# define INT_FAST16_MAX INT16_MAX
280# define UINT_FAST16_MAX UINT16_MAX
281# else
282# define INT_FAST16_MIN INT32_MIN
283# define INT_FAST16_MAX INT32_MAX
284# define UINT_FAST16_MAX UINT32_MAX
285# endif
286# ifndef __ASSEMBLER__
287typedef int32_t int_fast32_t;
288typedef uint32_t uint_fast32_t;
289# endif
290# define INT_FAST32_MIN INT32_MIN
291# define INT_FAST32_MAX INT32_MAX
292# define UINT_FAST32_MAX UINT32_MAX
293# ifndef __ASSEMBLER__
294typedef int64_t int_fast64_t;
295typedef uint64_t uint_fast64_t;
296# endif
297# define INT_FAST64_MIN INT64_MIN
298# define INT_FAST64_MAX INT64_MAX
299# define UINT_FAST64_MAX UINT64_MAX
300
301# else
302# error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
303# endif
304
305# endif /* !linux kernel or stuff */
306
307 /* pointer <-> integer types */
308# if (!defined(_MSC_VER) && !defined(__WATCOMC__) && !defined(__ASSEMBLER__)) || defined(DOXYGEN_RUNNING)
309# if ARCH_BITS == 32 \
310 || defined(RT_OS_LINUX) \
311 || defined(RT_OS_FREEBSD)
312# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
313typedef signed long intptr_t;
314# endif
315# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
316typedef unsigned long uintptr_t;
317# endif
318# else
319# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
320typedef int64_t intptr_t;
321# endif
322# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
323typedef uint64_t uintptr_t;
324# endif
325# endif
326# endif /* !_MSC_VER && !__WATCOMC__ && !__ASSEMLBER__ */
327
328#endif /* no system stdint.h */
329
330
331/*
332 * Make sure the [U]INTx_C(c) macros are present.
333 * For In C++ source the system stdint.h may have skipped these if it was
334 * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
335 */
336#if !defined(INT8_C) \
337 || !defined(INT16_C) \
338 || !defined(INT32_C) \
339 || !defined(INT64_C) \
340 || !defined(UINT8_C) \
341 || !defined(UINT16_C) \
342 || !defined(UINT32_C) \
343 || !defined(UINT64_C)
344# define INT8_C(Value) (Value)
345# define INT16_C(Value) (Value)
346# define UINT8_C(Value) (Value)
347# define UINT16_C(Value) (Value)
348# if ARCH_BITS != 16
349# define INT32_C(Value) (Value)
350# define UINT32_C(Value) (Value ## U)
351# define INT64_C(Value) (Value ## LL)
352# define UINT64_C(Value) (Value ## ULL)
353# else
354# define INT32_C(Value) (Value ## L)
355# define UINT32_C(Value) (Value ## UL)
356# define INT64_C(Value) (Value ## LL)
357# define UINT64_C(Value) (Value ## ULL)
358# endif
359#endif
360#if !defined(INTMAX_C) \
361 || !defined(UINTMAX_C)
362# define INTMAX_C(Value) INT64_C(Value)
363# define UINTMAX_C(Value) UINT64_C(Value)
364#endif
365
366
367/*
368 * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
369 * For In C++ source the system stdint.h may have skipped these if it was
370 * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
371 */
372#if !defined(INT8_MIN) \
373 || !defined(INT16_MIN) \
374 || !defined(INT32_MIN) \
375 || !defined(INT64_MIN) \
376 || !defined(INT8_MAX) \
377 || !defined(INT16_MAX) \
378 || !defined(INT32_MAX) \
379 || !defined(INT64_MAX) \
380 || !defined(UINT8_MAX) \
381 || !defined(UINT16_MAX) \
382 || !defined(UINT32_MAX) \
383 || !defined(UINT64_MAX)
384# define INT8_MIN (INT8_C(-0x7f) - 1)
385# define INT16_MIN (INT16_C(-0x7fff) - 1)
386# define INT32_MIN (INT32_C(-0x7fffffff) - 1)
387# define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
388# define INT8_MAX INT8_C(0x7f)
389# define INT16_MAX INT16_C(0x7fff)
390# define INT32_MAX INT32_C(0x7fffffff)
391# define INT64_MAX INT64_C(0x7fffffffffffffff)
392# define UINT8_MAX UINT8_C(0xff)
393# define UINT16_MAX UINT16_C(0xffff)
394# define UINT32_MAX UINT32_C(0xffffffff)
395# define UINT64_MAX UINT64_C(0xffffffffffffffff)
396#endif
397#if !defined(INTMAX_MIN) \
398 || !defined(INTMAX_MAX) \
399 || !defined(UINTMAX_MAX)
400# define INTMAX_MIN INT64_MIN
401# define INTMAX_MAX INT64_MAX
402# define UINTMAX_MAX UINT64_MAX
403#endif
404
405#endif /* !IPRT_INCLUDED_stdint_h */
406
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