blob: 3a9f502a7ea5edc6191392b0415dd8496053efca [file] [log] [blame]
José Fonseca70fe7c62013-03-12 11:17:49 +00001/**************************************************************************
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#ifndef _C99_COMPAT_H_
29#define _C99_COMPAT_H_
30
31
32/*
José Fonseca57cd1d12013-03-12 20:37:47 +000033 * MSVC hacks.
34 */
35#if defined(_MSC_VER)
36 /*
37 * Visual Studio 2012 will complain if we define the `inline` keyword, but
38 * actually it only supports the keyword on C++.
39 *
40 * We could skip this check by defining _ALLOW_KEYWORD_MACROS, but there is
41 * probably value in checking this for other keywords. So simply include
42 * the checking before we define it below.
43 */
44# if _MSC_VER >= 1700
45# include <xkeycheck.h>
46# endif
47
48 /*
49 * XXX: MSVC has a `__restrict` keyword, but it also has a
50 * `__declspec(restrict)` modifier, so it is impossible to define a
51 * `restrict` macro without interfering with the latter. Furthermore the
52 * MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
53 * macro. For now resolve this issue by redefining _CRTRESTRICT, but going
54 * forward we should probably should stop using restrict, especially
55 * considering that our code does not obbey strict aliasing rules any way.
56 */
57# include <crtdefs.h>
58# undef _CRTRESTRICT
59# define _CRTRESTRICT
60#endif
61
62
63/*
José Fonseca70fe7c62013-03-12 11:17:49 +000064 * C99 inline keyword
65 */
66#ifndef inline
67# ifdef __cplusplus
68 /* C++ supports inline keyword */
69# elif defined(__GNUC__)
70# define inline __inline__
71# elif defined(_MSC_VER)
72# define inline __inline
73# elif defined(__ICL)
74# define inline __inline
75# elif defined(__INTEL_COMPILER)
76 /* Intel compiler supports inline keyword */
77# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
78# define inline __inline
79# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
80 /* C99 supports inline keyword */
81# elif (__STDC_VERSION__ >= 199901L)
82 /* C99 supports inline keyword */
83# else
84# define inline
85# endif
86#endif
87
88
89/*
90 * C99 restrict keyword
91 *
92 * See also:
93 * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
94 */
95#ifndef restrict
96# if (__STDC_VERSION__ >= 199901L)
97 /* C99 */
98# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
99 /* C99 */
100# elif defined(__GNUC__)
101# define restrict __restrict__
102# elif defined(_MSC_VER)
103# define restrict __restrict
104# else
105# define restrict /* */
106# endif
107#endif
108
109
110/*
111 * C99 __func__ macro
112 */
113#ifndef __func__
114# if (__STDC_VERSION__ >= 199901L)
115 /* C99 */
116# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
117 /* C99 */
118# elif defined(__GNUC__)
119# if __GNUC__ >= 2
120# define __func__ __FUNCTION__
121# else
122# define __func__ "<unknown>"
123# endif
124# elif defined(_MSC_VER)
125# if _MSC_VER >= 1300
126# define __func__ __FUNCTION__
127# else
128# define __func__ "<unknown>"
129# endif
130# else
131# define __func__ "<unknown>"
132# endif
133#endif
134
135
José Fonseca57cd1d12013-03-12 20:37:47 +0000136/* Simple test case for debugging */
137#if 0
138static inline const char *
139test_c99_compat_h(const void * restrict a,
140 const void * restrict b)
141{
142 return __func__;
143}
144#endif
145
146
José Fonseca70fe7c62013-03-12 11:17:49 +0000147#endif /* _C99_COMPAT_H_ */