blob: f56f6f326f83ff7f58314fb46727dfdc06078e79 [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)
Jose Fonseca46110c52015-02-26 11:47:46 +000036
37# if _MSC_VER < 1500
38# error "Microsoft Visual Studio 2008 or higher required"
39# endif
40
José Fonseca57cd1d12013-03-12 20:37:47 +000041 /*
42 * Visual Studio 2012 will complain if we define the `inline` keyword, but
43 * actually it only supports the keyword on C++.
44 *
José Fonsecaa35a19a2013-03-14 17:40:14 +000045 * To avoid this the _ALLOW_KEYWORD_MACROS must be set.
José Fonseca57cd1d12013-03-12 20:37:47 +000046 */
José Fonsecaa35a19a2013-03-14 17:40:14 +000047# if (_MSC_VER >= 1700) && !defined(_ALLOW_KEYWORD_MACROS)
48# define _ALLOW_KEYWORD_MACROS
José Fonseca57cd1d12013-03-12 20:37:47 +000049# endif
50
51 /*
52 * XXX: MSVC has a `__restrict` keyword, but it also has a
53 * `__declspec(restrict)` modifier, so it is impossible to define a
54 * `restrict` macro without interfering with the latter. Furthermore the
55 * MSVC standard library uses __declspec(restrict) under the _CRTRESTRICT
56 * macro. For now resolve this issue by redefining _CRTRESTRICT, but going
57 * forward we should probably should stop using restrict, especially
58 * considering that our code does not obbey strict aliasing rules any way.
59 */
60# include <crtdefs.h>
61# undef _CRTRESTRICT
62# define _CRTRESTRICT
63#endif
64
65
66/*
José Fonseca70fe7c62013-03-12 11:17:49 +000067 * C99 inline keyword
68 */
69#ifndef inline
70# ifdef __cplusplus
71 /* C++ supports inline keyword */
72# elif defined(__GNUC__)
73# define inline __inline__
74# elif defined(_MSC_VER)
75# define inline __inline
76# elif defined(__ICL)
77# define inline __inline
78# elif defined(__INTEL_COMPILER)
79 /* Intel compiler supports inline keyword */
80# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
81# define inline __inline
82# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
83 /* C99 supports inline keyword */
84# elif (__STDC_VERSION__ >= 199901L)
85 /* C99 supports inline keyword */
86# else
87# define inline
88# endif
89#endif
90
91
92/*
93 * C99 restrict keyword
94 *
95 * See also:
96 * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html
97 */
98#ifndef restrict
99# if (__STDC_VERSION__ >= 199901L)
100 /* C99 */
101# elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
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(__SUNPRO_C) && defined(__C99FEATURES__)
120 /* C99 */
121# elif defined(__GNUC__)
Timothy Arceri5eec7c82014-12-12 19:05:22 +1100122# define __func__ __FUNCTION__
José Fonseca70fe7c62013-03-12 11:17:49 +0000123# elif defined(_MSC_VER)
Jose Fonseca46110c52015-02-26 11:47:46 +0000124# define __func__ __FUNCTION__
José Fonseca70fe7c62013-03-12 11:17:49 +0000125# else
126# define __func__ "<unknown>"
127# endif
128#endif
129
130
José Fonseca57cd1d12013-03-12 20:37:47 +0000131/* Simple test case for debugging */
132#if 0
133static inline const char *
134test_c99_compat_h(const void * restrict a,
135 const void * restrict b)
136{
137 return __func__;
138}
139#endif
140
141
José Fonseca70fe7c62013-03-12 11:17:49 +0000142#endif /* _C99_COMPAT_H_ */