VirtualBox

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

Last change on this file since 62592 was 62592, checked in by vboxsync, 8 years ago

IPRT: More unused parameters and undefined preprocessor macor warning (C4668) fixes/workarounds. The latter triggers in stdint.h from the compiler and in windows SDK/DDK headers.

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