VirtualBox

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

Last change on this file since 93483 was 93129, checked in by vboxsync, 3 years ago

include/iprt: Added iprt/nocrt/compiler/watcom.h and made a couple of related adjustments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/** @file
2 * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
3 */
4
5/*
6 * Copyright (C) 2009-2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef IPRT_INCLUDED_stdint_h
27#define IPRT_INCLUDED_stdint_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <iprt/cdefs.h>
33
34
35/*
36 * Use the stdint.h on systems that have one.
37 */
38#if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
39 && !(defined(RT_OS_FREEBSD) && defined(_KERNEL)) \
40 && !(defined(RT_OS_NETBSD) && defined(_KERNEL)) \
41 && RT_MSC_PREREQ_EX(RT_MSC_VER_VS2010, 1 /*non-msc*/) \
42 && !defined(__IBMC__) \
43 && !defined(__IBMCPP__) \
44 && !defined(IPRT_NO_CRT) \
45 && !defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
46 && !defined(DOXYGEN_RUNNING)
47
48# ifndef __STDC_CONSTANT_MACROS
49# define __STDC_CONSTANT_MACROS
50# endif
51# ifndef __STDC_LIMIT_MACROS
52# define __STDC_LIMIT_MACROS
53# endif
54# ifdef _MSC_VER
55# pragma warning(push)
56# pragma warning(disable:4668)
57# endif
58# include <stdint.h>
59# ifdef _MSC_VER
60# pragma warning(pop)
61# endif
62
63# if defined(RT_OS_DARWIN) && defined(KERNEL) && defined(RT_ARCH_AMD64)
64 /*
65 * Kludge to fix the incorrect 32-bit constant macros in
66 * Kernel.framework/Headers/stdin.h. uint32_t and int32_t are
67 * int not long as these macros use, which is significant when
68 * targeting AMD64. (10a222)
69 */
70# undef INT32_C
71# define INT32_C(Value) (Value)
72# undef UINT32_C
73# define UINT32_C(Value) (Value ## U)
74# endif /* 64-bit darwin kludge. */
75
76#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
77
78# ifndef __STDC_CONSTANT_MACROS
79# define __STDC_CONSTANT_MACROS
80# endif
81# ifndef __STDC_LIMIT_MACROS
82# define __STDC_LIMIT_MACROS
83# endif
84# include <sys/stdint.h>
85
86#elif defined(RT_OS_NETBSD) && 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#else /* No system stdint.h */
97
98/*
99 * Define the types we use.
100 * The linux kernel defines all these in linux/types.h, so skip it.
101 */
102# if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
103 || defined(IPRT_NO_CRT) \
104 || defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
105 || defined(DOXGEN_RUNNING)
106
107 /* Simplify the [u]int64_t type detection mess. */
108# undef IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
109# ifdef __IBMCPP__
110# if __IBMCPP__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
111# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
112# endif
113# endif
114# ifdef __IBMC__
115# if __IBMC__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
116# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
117# endif
118# endif
119
120 /* x-bit types */
121# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) \
122 || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64) \
123 || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
124# if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
125typedef signed char int8_t;
126# endif
127# if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
128typedef unsigned char uint8_t;
129# endif
130# if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
131typedef signed short int16_t;
132# endif
133# if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
134typedef unsigned short uint16_t;
135# endif
136# if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
137# if ARCH_BITS != 16
138typedef signed int int32_t;
139# else
140typedef signed long int32_t;
141# endif
142# endif
143# if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
144# if ARCH_BITS != 16
145typedef unsigned int uint32_t;
146# else
147typedef unsigned long uint32_t;
148# endif
149# endif
150# if defined(_MSC_VER)
151# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
152typedef signed _int64 int64_t;
153# endif
154# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
155typedef unsigned _int64 uint64_t;
156# endif
157# elif defined(__WATCOMC__)
158# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
159typedef signed __int64 int64_t;
160# endif
161# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
162typedef unsigned __int64 uint64_t;
163# endif
164# elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
165# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
166typedef struct { uint32_t lo; int32_t hi; } int64_t;
167# endif
168# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
169typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
170# endif
171# else /* Use long long for 64-bit types */
172# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
173typedef signed long long int64_t;
174# endif
175# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
176typedef unsigned long long uint64_t;
177# endif
178# endif
179
180 /* max integer types */
181# if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
182typedef int64_t intmax_t;
183# endif
184# if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
185typedef uint64_t uintmax_t;
186# endif
187
188# else
189# error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
190# endif
191
192# endif /* !linux kernel or stuff */
193
194 /* pointer <-> integer types */
195# if (!defined(_MSC_VER) && !defined(__WATCOMC__)) || defined(DOXYGEN_RUNNING)
196# if ARCH_BITS == 32 \
197 || defined(RT_OS_LINUX) \
198 || defined(RT_OS_FREEBSD)
199# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
200typedef signed long intptr_t;
201# endif
202# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
203typedef unsigned long uintptr_t;
204# endif
205# else
206# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
207typedef int64_t intptr_t;
208# endif
209# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
210typedef uint64_t uintptr_t;
211# endif
212# endif
213# endif /* !_MSC_VER */
214
215#endif /* no system stdint.h */
216
217
218/*
219 * Make sure the [U]INTx_C(c) macros are present.
220 * For In C++ source the system stdint.h may have skipped these if it was
221 * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
222 */
223#if !defined(INT8_C) \
224 || !defined(INT16_C) \
225 || !defined(INT32_C) \
226 || !defined(INT64_C) \
227 || !defined(INTMAX_C) \
228 || !defined(UINT8_C) \
229 || !defined(UINT16_C) \
230 || !defined(UINT32_C) \
231 || !defined(UINT64_C) \
232 || !defined(UINTMAX_C)
233# define INT8_C(Value) (Value)
234# define INT16_C(Value) (Value)
235# define UINT8_C(Value) (Value)
236# define UINT16_C(Value) (Value)
237# if ARCH_BITS != 16
238# define INT32_C(Value) (Value)
239# define UINT32_C(Value) (Value ## U)
240# define INT64_C(Value) (Value ## LL)
241# define UINT64_C(Value) (Value ## ULL)
242# else
243# define INT32_C(Value) (Value ## L)
244# define UINT32_C(Value) (Value ## UL)
245# define INT64_C(Value) (Value ## LL)
246# define UINT64_C(Value) (Value ## ULL)
247# endif
248# define INTMAX_C(Value) INT64_C(Value)
249# define UINTMAX_C(Value) UINT64_C(Value)
250#endif
251
252
253/*
254 * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
255 * For In C++ source the system stdint.h may have skipped these if it was
256 * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
257 */
258#if !defined(INT8_MIN) \
259 || !defined(INT16_MIN) \
260 || !defined(INT32_MIN) \
261 || !defined(INT64_MIN) \
262 || !defined(INT8_MAX) \
263 || !defined(INT16_MAX) \
264 || !defined(INT32_MAX) \
265 || !defined(INT64_MAX) \
266 || !defined(UINT8_MAX) \
267 || !defined(UINT16_MAX) \
268 || !defined(UINT32_MAX) \
269 || !defined(UINT64_MAX)
270# define INT8_MIN (INT8_C(-0x7f) - 1)
271# define INT16_MIN (INT16_C(-0x7fff) - 1)
272# define INT32_MIN (INT32_C(-0x7fffffff) - 1)
273# define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
274# define INT8_MAX INT8_C(0x7f)
275# define INT16_MAX INT16_C(0x7fff)
276# define INT32_MAX INT32_C(0x7fffffff)
277# define INT64_MAX INT64_C(0x7fffffffffffffff)
278# define UINT8_MAX UINT8_C(0xff)
279# define UINT16_MAX UINT16_C(0xffff)
280# define UINT32_MAX UINT32_C(0xffffffff)
281# define UINT64_MAX UINT64_C(0xffffffffffffffff)
282
283# define INTMAX_MIN INT64_MIN
284# define INTMAX_MAX INT64_MAX
285# define UINTMAX_MAX UINT64_MAX
286#endif
287
288#endif /* !IPRT_INCLUDED_stdint_h */
289
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