VirtualBox

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

Last change on this file since 77921 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/** @file
2 * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
3 */
4
5/*
6 * Copyright (C) 2009-2019 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) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
122# if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
123typedef signed char int8_t;
124# endif
125# if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
126typedef unsigned char uint8_t;
127# endif
128# if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
129typedef signed short int16_t;
130# endif
131# if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
132typedef unsigned short uint16_t;
133# endif
134# if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
135# if ARCH_BITS != 16
136typedef signed int int32_t;
137# else
138typedef signed long int32_t;
139# endif
140# endif
141# if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
142# if ARCH_BITS != 16
143typedef unsigned int uint32_t;
144# else
145typedef unsigned long uint32_t;
146# endif
147# endif
148# if defined(_MSC_VER)
149# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
150typedef signed _int64 int64_t;
151# endif
152# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
153typedef unsigned _int64 uint64_t;
154# endif
155# elif defined(__WATCOMC__)
156# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
157typedef signed __int64 int64_t;
158# endif
159# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
160typedef unsigned __int64 uint64_t;
161# endif
162# elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
163# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
164typedef struct { uint32_t lo; int32_t hi; } int64_t;
165# endif
166# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
167typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
168# endif
169# else /* Use long long for 64-bit types */
170# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
171typedef signed long long int64_t;
172# endif
173# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
174typedef unsigned long long uint64_t;
175# endif
176# endif
177
178 /* max integer types */
179# if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
180typedef int64_t intmax_t;
181# endif
182# if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
183typedef uint64_t uintmax_t;
184# endif
185
186# else
187# error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
188# endif
189
190# endif /* !linux kernel or stuff */
191
192 /* pointer <-> integer types */
193# if !defined(_MSC_VER) || defined(DOXYGEN_RUNNING)
194# if ARCH_BITS == 32 \
195 || defined(RT_OS_LINUX) \
196 || defined(RT_OS_FREEBSD)
197# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T)
198typedef signed long intptr_t;
199# endif
200# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T)
201typedef unsigned long uintptr_t;
202# endif
203# else
204# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T)
205typedef int64_t intptr_t;
206# endif
207# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T)
208typedef uint64_t uintptr_t;
209# endif
210# endif
211# endif /* !_MSC_VER */
212
213#endif /* no system stdint.h */
214
215
216/*
217 * Make sure the [U]INTx_C(c) macros are present.
218 * For In C++ source the system stdint.h may have skipped these if it was
219 * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
220 */
221#if !defined(INT8_C) \
222 || !defined(INT16_C) \
223 || !defined(INT32_C) \
224 || !defined(INT64_C) \
225 || !defined(INTMAX_C) \
226 || !defined(UINT8_C) \
227 || !defined(UINT16_C) \
228 || !defined(UINT32_C) \
229 || !defined(UINT64_C) \
230 || !defined(UINTMAX_C)
231# define INT8_C(Value) (Value)
232# define INT16_C(Value) (Value)
233# define UINT8_C(Value) (Value)
234# define UINT16_C(Value) (Value)
235# if ARCH_BITS != 16
236# define INT32_C(Value) (Value)
237# define UINT32_C(Value) (Value ## U)
238# define INT64_C(Value) (Value ## LL)
239# define UINT64_C(Value) (Value ## ULL)
240# else
241# define INT32_C(Value) (Value ## L)
242# define UINT32_C(Value) (Value ## UL)
243# define INT64_C(Value) (Value ## LL)
244# define UINT64_C(Value) (Value ## ULL)
245# endif
246# define INTMAX_C(Value) INT64_C(Value)
247# define UINTMAX_C(Value) UINT64_C(Value)
248#endif
249
250
251/*
252 * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
253 * For In C++ source the system stdint.h may have skipped these if it was
254 * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
255 */
256#if !defined(INT8_MIN) \
257 || !defined(INT16_MIN) \
258 || !defined(INT32_MIN) \
259 || !defined(INT64_MIN) \
260 || !defined(INT8_MAX) \
261 || !defined(INT16_MAX) \
262 || !defined(INT32_MAX) \
263 || !defined(INT64_MAX) \
264 || !defined(UINT8_MAX) \
265 || !defined(UINT16_MAX) \
266 || !defined(UINT32_MAX) \
267 || !defined(UINT64_MAX)
268# define INT8_MIN (INT8_C(-0x7f) - 1)
269# define INT16_MIN (INT16_C(-0x7fff) - 1)
270# define INT32_MIN (INT32_C(-0x7fffffff) - 1)
271# define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
272# define INT8_MAX INT8_C(0x7f)
273# define INT16_MAX INT16_C(0x7fff)
274# define INT32_MAX INT32_C(0x7fffffff)
275# define INT64_MAX INT64_C(0x7fffffffffffffff)
276# define UINT8_MAX UINT8_C(0xff)
277# define UINT16_MAX UINT16_C(0xffff)
278# define UINT32_MAX UINT32_C(0xffffffff)
279# define UINT64_MAX UINT64_C(0xffffffffffffffff)
280
281# define INTMAX_MIN INT64_MIN
282# define INTMAX_MAX INT64_MAX
283# define UINTMAX_MAX UINT64_MAX
284#endif
285
286#endif /* !IPRT_INCLUDED_stdint_h */
287
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