1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * Copyright 2007-2013 VMware, Inc.
|
---|
4 | * All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
7 | * copy of this software and associated documentation files (the
|
---|
8 | * "Software"), to deal in the Software without restriction, including
|
---|
9 | * without limitation the rights to use, copy, modify, merge, publish,
|
---|
10 | * distribute, sub license, and/or sell copies of the Software, and to
|
---|
11 | * permit persons to whom the Software is furnished to do so, subject to
|
---|
12 | * the following conditions:
|
---|
13 | *
|
---|
14 | * The above copyright notice and this permission notice (including the
|
---|
15 | * next paragraph) shall be included in all copies or substantial portions
|
---|
16 | * of the Software.
|
---|
17 | *
|
---|
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
---|
19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
---|
20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
---|
21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
---|
22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
---|
23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
---|
24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
---|
25 | *
|
---|
26 | **************************************************************************/
|
---|
27 |
|
---|
28 | #include "no_extern_c.h"
|
---|
29 |
|
---|
30 | #ifndef _C99_COMPAT_H_
|
---|
31 | #define _C99_COMPAT_H_
|
---|
32 |
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * MSVC hacks.
|
---|
36 | */
|
---|
37 | #if defined(_MSC_VER)
|
---|
38 |
|
---|
39 | # if _MSC_VER < 1900
|
---|
40 | # error "Microsoft Visual Studio 2015 or higher required"
|
---|
41 | # endif
|
---|
42 |
|
---|
43 | /*
|
---|
44 | * Visual Studio will complain if we define the `inline` keyword, but
|
---|
45 | * actually it only supports the keyword on C++.
|
---|
46 | *
|
---|
47 | * To avoid this the _ALLOW_KEYWORD_MACROS must be set.
|
---|
48 | */
|
---|
49 | # if !defined(_ALLOW_KEYWORD_MACROS)
|
---|
50 | # define _ALLOW_KEYWORD_MACROS
|
---|
51 | # endif
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * XXX: MSVC has a `__restrict` keyword, but it also has a
|
---|
55 | * `__declspec(restrict)` modifier, so it is impossible to define a
|
---|
56 | * `restrict` macro without interfering with the latter. Furthermore the
|
---|
57 | * MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
|
---|
58 | * macro. For now resolve this issue by redefining _CRTRESTRICT, but going
|
---|
59 | * forward we should probably should stop using restrict, especially
|
---|
60 | * considering that our code does not obbey strict aliasing rules any way.
|
---|
61 | */
|
---|
62 | # ifndef IPRT_NO_CRT /* VBox */
|
---|
63 | # include <crtdefs.h>
|
---|
64 | # undef _CRTRESTRICT
|
---|
65 | # define _CRTRESTRICT
|
---|
66 | # endif /* VBox */
|
---|
67 | #endif
|
---|
68 |
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * C99 inline keyword
|
---|
72 | */
|
---|
73 | #ifndef inline
|
---|
74 | # ifdef __cplusplus
|
---|
75 | /* C++ supports inline keyword */
|
---|
76 | # elif defined(__GNUC__)
|
---|
77 | # define inline __inline__
|
---|
78 | # elif defined(_MSC_VER)
|
---|
79 | # define inline __inline
|
---|
80 | # elif defined(__ICL)
|
---|
81 | # define inline __inline
|
---|
82 | # elif defined(__INTEL_COMPILER)
|
---|
83 | /* Intel compiler supports inline keyword */
|
---|
84 | # elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
|
---|
85 | # define inline __inline
|
---|
86 | # elif (__STDC_VERSION__ >= 199901L)
|
---|
87 | /* C99 supports inline keyword */
|
---|
88 | # else
|
---|
89 | # define inline
|
---|
90 | # endif
|
---|
91 | #endif
|
---|
92 |
|
---|
93 |
|
---|
94 | /*
|
---|
95 | * C99 restrict keyword
|
---|
96 | *
|
---|
97 | * See also:
|
---|
98 | * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
|
---|
99 | */
|
---|
100 | #ifndef restrict
|
---|
101 | # if (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus)
|
---|
102 | /* C99 */
|
---|
103 | # elif defined(__GNUC__)
|
---|
104 | # define restrict __restrict__
|
---|
105 | # elif defined(_MSC_VER)
|
---|
106 | # define restrict __restrict
|
---|
107 | # else
|
---|
108 | # define restrict /* */
|
---|
109 | # endif
|
---|
110 | #endif
|
---|
111 |
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * C99 __func__ macro
|
---|
115 | */
|
---|
116 | #ifndef __func__
|
---|
117 | # if (__STDC_VERSION__ >= 199901L)
|
---|
118 | /* C99 */
|
---|
119 | # elif defined(__GNUC__)
|
---|
120 | # define __func__ __FUNCTION__
|
---|
121 | # elif defined(_MSC_VER)
|
---|
122 | # define __func__ __FUNCTION__
|
---|
123 | # else
|
---|
124 | # define __func__ "<unknown>"
|
---|
125 | # endif
|
---|
126 | #endif
|
---|
127 |
|
---|
128 |
|
---|
129 | /* Simple test case for debugging */
|
---|
130 | #if 0
|
---|
131 | static inline const char *
|
---|
132 | test_c99_compat_h(const void * restrict a,
|
---|
133 | const void * restrict b)
|
---|
134 | {
|
---|
135 | return __func__;
|
---|
136 | }
|
---|
137 | #endif
|
---|
138 |
|
---|
139 |
|
---|
140 | #endif /* _C99_COMPAT_H_ */
|
---|