]> pd.if.org Git - pdclib/blob - internals/_PDCLIB_aux.h
(merge)
[pdclib] / internals / _PDCLIB_aux.h
1 #ifndef _PDCLIB_AUX_H
2 #define _PDCLIB_AUX_H
3
4 /* Auxiliary PDCLib code <_PDCLIB_aux.h>
5
6    This file is part of the Public Domain C Library (PDCLib).
7    Permission is granted to use, modify, and / or redistribute at will.
8 */
9
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 /* -------------------------------------------------------------------------- */
14
15 /* -------------------------------------------------------------------------- */
16 /* Standard Version                                                           */
17 /* -------------------------------------------------------------------------- */
18
19 /* Many a compiler gets this wrong, so you might have to hardcode it instead. */
20
21 #if __STDC__ != 1
22 #error Compiler does not define _ _STDC_ _ to 1 (not standard-compliant)!
23 #endif
24
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
35 #else
36         #error Unsupported _ _STDC_VERSION_ _ (__STDC_VERSION__) (supported: ISO/IEC 9899:1990, 9899/AMD1:1995, 9899:1999, 9899:2011).
37 #endif
38
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
47         #endif
48 #elif __cplusplus == 199711L
49    #define _PDCLIB_CXX_VERSION 1997
50 #else
51    #error Unsupported _ _cplusplus (__cplusplus) (supported: ISO/IEC 14882:1997, ISO/IEC 14882:2011).
52 #endif
53
54 #if _PDCLIB_C_VERSION >= 1999 || defined(__cplusplus)
55         #ifndef __cplusplus
56                 #define _PDCLIB_restrict restrict
57         #endif
58         #define _PDCLIB_inline   inline
59 #endif
60
61 #if _PDCLIB_CXX_VERSION >= 2011
62   // Hold off on C++ attribute syntax for now
63   // #define _PDCLIB_noreturn [[noreturn]]
64 #elif _PDCLIB_C_VERSION >= 2011
65         #define _PDCLIB_noreturn _Noreturn
66 #endif
67
68 #ifdef _WIN32
69    #define _PDCLIB_EXPORT __declspec(dllexport)
70    #define _PDCLIB_IMPORT __declspec(dllimport)
71 #endif
72
73 #ifdef __GNUC__
74         #ifndef _PDCLIB_EXPORT
75                 #define _PDCLIB_EXPORT __attribute__((__visibility__("protected")))
76         #endif
77
78         #ifndef _PDCLIB_IMPORT
79                 #define _PDCLIB_IMPORT
80         #endif
81
82         #ifndef _PDCLIB_HIDDEN
83                 #define _PDCLIB_HIDDEN __attribute__((__visibility__("hidden")))
84         #endif
85
86         #ifndef _PDCLIB_restrict
87                 #define _PDCLIB_restrict __restrict
88         #endif
89
90         #ifndef _PDCLIB_inline
91                 #define _PDCLIB_inline __inline
92         #endif
93
94         #ifndef _PDCLIB_noreturn
95     /* If you don't use __noreturn__, then stdnoreturn.h will break things! */
96                 #define _PDCLIB_noreturn __attribute__((__noreturn__))
97         #endif
98 #endif
99
100 #ifndef _PDCLIB_EXPORT
101         #define _PDCLIB_EXPORT
102 #endif
103 #ifndef _PDCLIB_IMPORT
104         #define _PDCLIB_IMPORT
105 #endif
106 #ifndef _PDCLIB_HIDDEN
107         #define _PDCLIB_HIDDEN
108 #endif
109
110 #if defined(_PDCLIB_SHARED) 
111         #if defined(_PDCLIB_BUILD)
112                 #define _PDCLIB_API _PDCLIB_EXPORT
113         #else
114                 #define _PDCLIB_API _PDCLIB_IMPORT
115         #endif
116 #else
117         #define _PDCLIB_API
118 #endif
119
120 #ifndef _PDCLIB_restrict
121         #define _PDCLIB_restrict
122 #endif
123
124 #ifndef _PDCLIB_inline
125         #define _PDCLIB_inline
126 #endif
127
128 #ifndef _PDCLIB_noreturn
129         #define _PDCLIB_noreturn
130 #endif
131
132 #ifndef __STDC_HOSTED__
133 #error Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)!
134 #elif __STDC_HOSTED__ == 0
135 #define _PDCLIB_HOSTED 0
136 #elif __STDC_HOSTED__ == 1
137 #define _PDCLIB_HOSTED 1
138 #else
139 #error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)!
140 #endif
141
142 #ifdef __cplusplus
143         #define _PDCLIB_BEGIN_EXTERN_C extern "C" {
144         #define _PDCLIB_END_EXTERN_C }
145 #else
146    #define _PDCLIB_BEGIN_EXTERN_C
147    #define _PDCLIB_END_EXTERN_C
148 #endif
149
150 /*#if _PDCLIB_C_VERSION != 1999
151 #error PDCLib might not be fully conforming to either C89 or C95 prior to v2.x.
152 #endif*/
153
154 /* -------------------------------------------------------------------------- */
155 /* Helper macros:                                                             */
156 /* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending  */
157 /* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */
158 /* -------------------------------------------------------------------------- */
159
160 #define _PDCLIB_cc( x, y )     x ## y
161 #define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y )
162
163 #define _PDCLIB_symbol2value( x ) #x
164 #define _PDCLIB_symbol2string( x ) _PDCLIB_symbol2value( x )
165
166 /* Feature test macros
167  *
168  * All of the feature test macros come in the following forms
169  *   _PDCLIB_*_MIN(min):            Available in versions > min
170  *   _PDCLIB_*_MINMAX(min, max):    Available in versions > min < max
171  *   _PDCLIB_*_MAX(max):            Availabel in versions < max
172  *
173  * The defined tests are:
174  *   C:     C standard versions 
175  *              1990, 1995, 1999, 2011
176  *   CXX:   C++ standard versions 
177  *              1997, 2011
178  *   POSIX: POSIX extension versions.
179  *              1 (POSIX.2), 2 (POSIX.2), 199309L (POSIX.1b), 
180  *              199506L (POSIX.1c), 200112L (2001), 200809L (2008)
181  *   XOPEN: X/Open System Interface (XSI)/Single Unix Specification
182  *              0 (XPG4), 500 (SUSv2/UNIX98), 600 (SUSv3/UNIX03), 700 (SUSv4)
183  *
184  * PDCLib does not attempt or claim POSIX comformance, but makes available these
185  * extensions as
186  *   (a) useful, and
187  *   (b) 
188  */
189 #define _PDCLIB_C_MIN(min)         _PDCLIB_C_MINMAX(min, 3000)
190 #define _PDCLIB_CXX_MIN(min)     _PDCLIB_CXX_MINMAX(min, 3000)
191 #define _PDCLIB_XOPEN_MIN(min) _PDCLIB_XOPEN_MINMAX(min, 30000000)
192 #define _PDCLIB_POSIX_MIN(min) _PDCLIB_POSIX_MINMAX(min, 30000000)
193 #define _PDCLIB_C_MAX(max)         _PDCLIB_C_MINMAX(0, max)
194 #define _PDCLIB_CXX_MAX(max)     _PDCLIB_CXX_MINMAX(0, max)
195 #define _PDCLIB_XOPEN_MAX(max) _PDCLIB_XOPEN_MINMAX(0, max)
196 #define _PDCLIB_POSIX_MAX(max) _PDCLIB_POSIX_MINMAX(0, max)
197 #if defined(_PDCLIB_EXTENSIONS) || defined(_PDCLIB_BUILD)
198     #define _PDCLIB_C_MINMAX(min, max) 1
199     #define _PDCLIB_CXX_MINMAX(min, max) 1
200     #define _PDCLIB_POSIX_MINMAX(min, max) 1
201     #define _PDCLIB_XOPEN_MINMAX(min, max) 1
202 #else
203     #define _PDCLIB_C_MINMAX(min, max) \
204         (_PDCLIB_C_VERSION >= (min) && _PDCLIB_C_VERSION <= (max))
205     #define _PDCLIB_CXX_MINMAX(min, max) \
206         (_PDCLIB_CXX_VERSION >= (min) && _PDCLIB_CXX_VERSION <= (max))
207     #define _PDCLIB_XOPEN_MINMAX(min, max) \
208         (defined(_XOPEN_SOURCE) \
209             && _XOPEN_SOURCE >= (min) && _XOPEN_SOURCE <= (max))
210     #define _PDCLIB_POSIX_MINMAX(min, max) \
211         (defined(_POSIX_C_SOURCE) \
212             && _POSIX_C_SOURCE >= (min) && _POSIX_C_SOURCE <= (max))
213
214     #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE-1 == -1)
215         /* If _XOPEN_SOURCE is defined as empty, redefine here as zero */
216         #undef _XOPEN_SOURCE
217         #define _XOPEN_SOURCE 0
218     #endif
219
220     #if _PDCLIB_XOPEN_MIN(700) && !_PDCLIB_POSIX_MIN(200809L)
221         #undef _POSIX_C_SOURCE
222         #define _POSIX_C_SOURCE 2008098L    
223     #elif _PDCLIB_XOPEN_MIN(600) && !_PDCLIB_POSIX_MIN(200112L)
224         #undef _POSIX_C_SOURCE
225         #define _POSIX_C_SOURCE 200112L
226     #elif _PDCLIB_XOPEN_MIN(0) && !_PDCLIB_POSIX_MIN(2)
227         #undef _POSIX_C_SOURCE
228         #define _POSIX_C_SOURCE 2
229     #endif
230
231     #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
232         #define _POSIX_C_SOURCE 1
233     #endif
234 #endif
235
236 #endif