4 /* Auxiliary PDCLib code <_PDCLIB_aux.h>
6 This file is part of the Public Domain C Library (PDCLib).
7 Permission is granted to use, modify, and / or redistribute at will.
10 /* -------------------------------------------------------------------------- */
11 /* You should not have to edit anything in this file; if you DO have to, it */
12 /* would be considered a bug / missing feature: notify the author(s). */
13 /* -------------------------------------------------------------------------- */
15 /* -------------------------------------------------------------------------- */
16 /* Standard Version */
17 /* -------------------------------------------------------------------------- */
19 /* Many a compiler gets this wrong, so you might have to hardcode it instead. */
22 #error Compiler does not define _ _STDC_ _ to 1 (not standard-compliant)!
25 #if defined(_PDCLIB_C_VERSION)
26 /* Pass - conditional simplification case */
27 #elif !defined(__STDC_VERSION__)
28 #define _PDCLIB_C_VERSION 1990
29 #elif __STDC_VERSION__ == 199409L
30 #define _PDCLIB_C_VERSION 1995
31 #elif __STDC_VERSION__ == 199901L
32 #define _PDCLIB_C_VERSION 1999
33 #elif __STDC_VERSION__ == 201112L
34 #define _PDCLIB_C_VERSION 2011
36 #error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, 9899:1999, 9899:2011).
39 #if !defined(__cplusplus) || defined(_PDCLIB_CXX_VERSION)
40 #define _PDCLIB_CXX_VERSION 0
41 #elif __cplusplus == 201103L
42 #define _PDCLIB_CXX_VERSION 2011
43 /* TODO: Do we want this? */
44 #if _PDCLIB_C_VERSION < 2011
45 #undef _PDCLIB_C_VERSION
46 #define _PDCLIB_C_VERSION 2011
48 #elif __cplusplus == 199711L
49 #define _PDCLIB_CXX_VERSION 1997
51 #error Unsupported _ _cplusplus (__cplusplus) (supported: ISO/IEC 14882:1997, ISO/IEC 14882:2011).
54 #if _PDCLIB_C_VERSION >= 1999 || defined(__cplusplus)
56 #define _PDCLIB_restrict restrict
58 #define _PDCLIB_inline inline
61 #if _PDCLIB_CXX_VERSION >= 2011
62 #define _PDCLIB_nothrow noexcept
63 #define _PDCLIB_noexcept(x) noexcept(x)
64 #elif _PDCLIB_CXX_VERSION
65 #define _PDCLIB_nothrow throw()
66 #define _PDCLIB_noexcept
69 #if _PDCLIB_CXX_VERSION >= 2011
70 // Hold off on C++ attribute syntax for now
71 // #define _PDCLIB_noreturn [[noreturn]]
72 #elif _PDCLIB_C_VERSION >= 2011
73 #define _PDCLIB_noreturn _Noreturn
77 #define _PDCLIB_EXPORT __declspec(dllexport)
78 #define _PDCLIB_IMPORT __declspec(dllimport)
82 #ifndef _PDCLIB_EXPORT
83 #define _PDCLIB_EXPORT __attribute__((__visibility__("protected")))
86 #ifndef _PDCLIB_IMPORT
87 #define _PDCLIB_IMPORT
90 #ifndef _PDCLIB_HIDDEN
91 #define _PDCLIB_HIDDEN __attribute__((__visibility__("hidden")))
94 #ifndef _PDCLIB_nothrow
95 #define _PDCLIB_nothrow __attribute__((__nothrow__))
96 #define _PDCLIB_noexcept
99 #ifndef _PDCLIB_restrict
100 #define _PDCLIB_restrict __restrict
103 #ifndef _PDCLIB_inline
104 #define _PDCLIB_inline __inline
107 #ifndef _PDCLIB_noreturn
108 /* If you don't use __noreturn__, then stdnoreturn.h will break things! */
109 #define _PDCLIB_noreturn __attribute__((__noreturn__))
113 #ifndef _PDCLIB_nothrow
114 #define _PDCLIB_nothrow
115 #define _PDCLIB_noexcept
118 #ifndef _PDCLIB_EXPORT
119 #define _PDCLIB_EXPORT
121 #ifndef _PDCLIB_IMPORT
122 #define _PDCLIB_IMPORT
124 #ifndef _PDCLIB_HIDDEN
125 #define _PDCLIB_HIDDEN
128 #if defined(_PDCLIB_SHARED)
129 #if defined(_PDCLIB_BUILD)
130 #define _PDCLIB_API _PDCLIB_EXPORT
132 #define _PDCLIB_API _PDCLIB_IMPORT
138 #ifndef _PDCLIB_restrict
139 #define _PDCLIB_restrict
142 #ifndef _PDCLIB_inline
143 #define _PDCLIB_inline
146 #ifndef _PDCLIB_noreturn
147 #define _PDCLIB_noreturn
150 #ifndef __STDC_HOSTED__
151 #error Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)!
152 #elif __STDC_HOSTED__ == 0
153 #define _PDCLIB_HOSTED 0
154 #elif __STDC_HOSTED__ == 1
155 #define _PDCLIB_HOSTED 1
157 #error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)!
161 #define _PDCLIB_BEGIN_EXTERN_C extern "C" {
162 #define _PDCLIB_END_EXTERN_C }
164 #define _PDCLIB_BEGIN_EXTERN_C
165 #define _PDCLIB_END_EXTERN_C
168 /*#if _PDCLIB_C_VERSION != 1999
169 #error PDCLib might not be fully conforming to either C89 or C95 prior to v2.x.
172 /* -------------------------------------------------------------------------- */
174 /* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending */
175 /* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */
176 /* -------------------------------------------------------------------------- */
178 #define _PDCLIB_cc( x, y ) x ## y
179 #define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y )
180 #define _PDCLIB_concat3( x, y, z ) _PDCLIB_concat( _PDCLIB_concat( x, y ), z )
182 #define _PDCLIB_symbol2value( x ) #x
183 #define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x )
185 /* Feature test macros
187 * All of the feature test macros come in the following forms
188 * _PDCLIB_*_MIN(min): Available in versions > min
189 * _PDCLIB_*_MINMAX(min, max): Available in versions > min < max
190 * _PDCLIB_*_MAX(max): Availabel in versions < max
192 * The defined tests are:
193 * C: C standard versions
194 * 1990, 1995, 1999, 2011
195 * CXX: C++ standard versions
197 * POSIX: POSIX extension versions.
198 * 1 (POSIX.2), 2 (POSIX.2), 199309L (POSIX.1b),
199 * 199506L (POSIX.1c), 200112L (2001), 200809L (2008)
200 * XOPEN: X/Open System Interface (XSI)/Single Unix Specification
201 * 0 (XPG4), 500 (SUSv2/UNIX98), 600 (SUSv3/UNIX03), 700 (SUSv4)
203 * PDCLib does not attempt or claim POSIX comformance, but makes available these
208 #define _PDCLIB_C_MIN(min) _PDCLIB_C_MINMAX(min, 3000)
209 #define _PDCLIB_CXX_MIN(min) _PDCLIB_CXX_MINMAX(min, 3000)
210 #define _PDCLIB_XOPEN_MIN(min) _PDCLIB_XOPEN_MINMAX(min, 30000000)
211 #define _PDCLIB_POSIX_MIN(min) _PDCLIB_POSIX_MINMAX(min, 30000000)
212 #define _PDCLIB_C_MAX(max) _PDCLIB_C_MINMAX(0, max)
213 #define _PDCLIB_CXX_MAX(max) _PDCLIB_CXX_MINMAX(0, max)
214 #define _PDCLIB_XOPEN_MAX(max) _PDCLIB_XOPEN_MINMAX(0, max)
215 #define _PDCLIB_POSIX_MAX(max) _PDCLIB_POSIX_MINMAX(0, max)
216 #if defined(_PDCLIB_EXTENSIONS) || defined(_PDCLIB_BUILD)
217 #define _PDCLIB_C_MINMAX(min, max) 1
218 #define _PDCLIB_CXX_MINMAX(min, max) 1
219 #define _PDCLIB_POSIX_MINMAX(min, max) 1
220 #define _PDCLIB_XOPEN_MINMAX(min, max) 1
222 #define _PDCLIB_C_MINMAX(min, max) \
223 (_PDCLIB_C_VERSION >= (min) && _PDCLIB_C_VERSION <= (max))
224 #define _PDCLIB_CXX_MINMAX(min, max) \
225 (_PDCLIB_CXX_VERSION >= (min) && _PDCLIB_CXX_VERSION <= (max))
226 #define _PDCLIB_XOPEN_MINMAX(min, max) \
227 (defined(_XOPEN_SOURCE) \
228 && _XOPEN_SOURCE >= (min) && _XOPEN_SOURCE <= (max))
229 #define _PDCLIB_POSIX_MINMAX(min, max) \
230 (defined(_POSIX_C_SOURCE) \
231 && _POSIX_C_SOURCE >= (min) && _POSIX_C_SOURCE <= (max))
233 #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE-1 == -1)
234 /* If _XOPEN_SOURCE is defined as empty, redefine here as zero */
236 #define _XOPEN_SOURCE 0
239 #if _PDCLIB_XOPEN_MIN(700) && !_PDCLIB_POSIX_MIN(200809L)
240 #undef _POSIX_C_SOURCE
241 #define _POSIX_C_SOURCE 2008098L
242 #elif _PDCLIB_XOPEN_MIN(600) && !_PDCLIB_POSIX_MIN(200112L)
243 #undef _POSIX_C_SOURCE
244 #define _POSIX_C_SOURCE 200112L
245 #elif _PDCLIB_XOPEN_MIN(0) && !_PDCLIB_POSIX_MIN(2)
246 #undef _POSIX_C_SOURCE
247 #define _POSIX_C_SOURCE 2
250 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
251 #define _POSIX_C_SOURCE 1