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