1 /**************************************************************************
2 * compiler.h -- C++ Compiler Portability Macros
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 **************************************************************************/
24 * A set of defines to encapsulate compiler and platform differences.
25 * Please refer to the source code for full documentation on this file.
27 * Here is a summary of what this file does.
29 * (1) Defines macros for some STL includes which may be affected
30 * by file name length limitations.
32 * (2) Defines macros for some features not supported by all C++ compilers.
34 * (3) Defines 'explicit' as a null macro if the compiler doesn't support
35 * the explicit keyword.
37 * (4) Defines 'typename' as a null macro if the compiler doesn't support
38 * the typename keyword.
40 * (5) Defines bool, true and false if the compiler doesn't do so.
42 * (6) Defines SG_EXPLICIT_FUNCTION_TMPL_ARGS if the compiler
43 * supports calling a function template by providing its template
44 * arguments explicitly.
46 * (7) Defines SG_NEED_AUTO_PTR if STL doesn't provide auto_ptr<>.
48 * (8) Defines SG_NO_ARROW_OPERATOR if the compiler is unable
49 * to support operator->() for iterators.
51 * (9) Defines SG_USE_EXCEPTIONS if the compiler supports exceptions.
52 * Note: no FlightGear code uses exceptions.
54 * (10) Define SG_NAMESPACES if the compiler supports namespaces.
56 * (11) SG_MATH_FN_IN_NAMESPACE_STD -- not used??
58 * (12) Define SG_HAVE_STD if std namespace is supported.
60 * (13) Defines SG_CLASS_PARTIAL_SPECIALIZATION if the compiler
61 * supports partial specialization of class templates.
63 * (14) Defines SG_HAVE_STD_INCLUDES to use ISO C++ Standard headers.
65 * (15) Defines SG_HAVE_STREAMBUF if <streambuf> of <streambuf.h> are present.
67 * (16) Define SG_MATH_EXCEPTION_CLASH if math.h defines an exception class
68 * that clashes with the one defined in <stdexcept>.
71 #ifndef _SG_COMPILER_H
72 #define _SG_COMPILER_H
75 * Helper macro SG_STRINGIZE:
76 * Converts the parameter X to a string after macro replacement
77 * on X has been performed.
79 #define SG_STRINGIZE(X) SG_DO_STRINGIZE(X)
80 #define SG_DO_STRINGIZE(X) #X
84 # if __GNUC_MINOR__ < 8
87 # define STL_ALGORITHM <algorithm>
88 # define STL_FUNCTIONAL <functional>
89 # define STL_IOMANIP <iomanip.h>
90 # define STL_IOSTREAM <iostream.h>
91 # define STL_ITERATOR <iterator.h>
92 # define STL_FSTREAM <fstream.h>
93 # define STL_STDEXCEPT <stdexcept>
94 # define STL_STRING <string>
95 # define STL_STRSTREAM <strstream.h>
97 # define SG_NEED_AUTO_PTR
98 # define SG_NO_DEFAULT_TEMPLATE_ARGS
99 # define SG_INCOMPLETE_FUNCTIONAL
100 # define SG_NO_ARROW_OPERATOR
102 # elif __GNUC_MINOR__ >= 8
104 // g++-2.8.x and egcs-1.x
105 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
106 # define SG_NEED_AUTO_PTR
107 # define SG_MEMBER_TEMPLATES
108 # define SG_NAMESPACES
110 # define SG_HAVE_STREAMBUF
111 # define SG_CLASS_PARTIAL_SPECIALIZATION
113 # define STL_ALGORITHM <algorithm>
114 # define STL_FUNCTIONAL <functional>
115 # define STL_IOMANIP <iomanip>
116 # define STL_IOSTREAM <iostream>
117 # define STL_ITERATOR <iterator>
118 # define STL_FSTREAM <fstream>
119 # define STL_STDEXCEPT <stdexcept>
120 # define STL_STRING <string>
121 # define STL_STRSTREAM <strstream>
126 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
127 # define SG_NEED_AUTO_PTR
128 # define SG_MEMBER_TEMPLATES
129 # define SG_NAMESPACES
131 # define SG_HAVE_STREAMBUF
132 # define SG_CLASS_PARTIAL_SPECIALIZATION
133 # define SG_HAVE_STD_INCLUDES
135 # define STL_ALGORITHM <algorithm>
136 # define STL_FUNCTIONAL <functional>
137 # define STL_IOMANIP <iomanip>
138 # define STL_IOSTREAM <iostream>
139 # define STL_ITERATOR <iterator>
140 # define STL_FSTREAM <fstream>
141 # define STL_STDEXCEPT <stdexcept>
142 # define STL_STRING <string>
143 # define STL_STRSTREAM <strstream>
146 # error Time to upgrade. GNU compilers < 2.7 not supported
149 # define SG_COMPILER "GNU C++ version " SG_STRINGIZE(__GNUC__) "." SG_STRINGIZE(__GNUC_MINOR__)
153 #if defined( __MINGW32__ )
154 # define bcopy(from, to, n) memcpy(to, from, n)
155 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
161 # define SG_NAMESPACES
163 # define SG_HAVE_STREAMBUF
164 # define SG_HAVE_TRAITS
165 # define SG_HAVE_STD_INCLUDES
167 # define STL_ALGORITHM <algorithm>
168 # define STL_FUNCTIONAL <functional>
169 # define STL_IOMANIP <iomanip>
170 # define STL_IOSTREAM <iostream>
171 # define STL_ITERATOR <iterator>
172 # define STL_FSTREAM <fstream>
173 # define STL_STDEXCEPT <stdexcept>
174 # define STL_STRING <string>
175 # define STL_STRSTREAM <strstream>
177 # define SG_COMPILER "Kai C++ version " SG_STRINGIZE(__KCC_VERSION)
184 #if defined(__MWERKS__)
186 CodeWarrior compiler from Metrowerks, Inc.
188 # define SG_HAVE_TRAITS
189 # define SG_HAVE_STD_INCLUDES
191 # define SG_NAMESPACES
193 # define STL_ALGORITHM <algorithm>
194 # define STL_FUNCTIONAL <functional>
195 # define STL_IOMANIP <iomanip>
196 # define STL_IOSTREAM <iostream>
197 # define STL_ITERATOR <iterator>
198 # define STL_FSTREAM <fstream>
199 # define STL_STDEXCEPT <stdexcept>
200 # define STL_STRING <string>
203 # define bcopy(from, to, n) memcpy(to, from, n)
205 // -rp- please use FG_MEM_COPY everywhere !
206 // #define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
208 // -dw- currently used glut has no game mode stuff
209 # define GLUT_WRONG_VERSION
211 # define SG_COMPILER "Metrowerks CodeWarrior C++ version " SG_STRINGIZE(__MWERKS__)
216 // Microsoft compilers.
219 # define bcopy(from, to, n) memcpy(to, from, n)
220 # define FG_MEM_COPY(to,from,n) memcpy(to, from, n)
222 # if _MSC_VER == 1200 // msvc++ 6.0
223 # define SG_NAMESPACES
225 # define SG_HAVE_STD_INCLUDES
226 # define SG_HAVE_STREAMBUF
228 # define STL_ALGORITHM <algorithm>
229 # define STL_FUNCTIONAL <functional>
230 # define STL_IOMANIP <iomanip>
231 # define STL_IOSTREAM <iostream>
232 # define STL_ITERATOR <iterator>
233 # define STL_FSTREAM <fstream>
234 # define STL_STDEXCEPT <stdexcept>
235 # define STL_STRING <string>
236 # define STL_STRSTREAM <strstream>
238 # define SG_NO_INCLASS_MEMBER_INITIALIZATION
240 // disable min/max macros if defined:
251 # pragma warning(disable: 4786) // identifier was truncated to '255' characters
252 # pragma warning(disable: 4244) // conversion from double to float
253 # pragma warning(disable: 4305) //
256 # error What version of MSVC++ is this?
259 # define SG_COMPILER "Microsoft Visual C++ version " SG_STRINGIZE(_MSC_VER)
264 # if defined(HAVE_SGI_STL_PORT)
266 // Use quotes around long file names to get around Borland's include hackery
268 # define STL_ALGORITHM "algorithm"
269 # define STL_FUNCTIONAL "functional"
271 # define SG_MATH_EXCEPTION_CLASH
275 # define STL_ALGORITHM <algorithm>
276 # define STL_FUNCTIONAL <functional>
277 # define STL_IOMANIP <iomanip>
278 # define STL_STDEXCEPT <stdexcept>
279 # define STL_STRSTREAM <strstream>
281 # define SG_INCOMPLETE_FUNCTIONAL
283 # endif // HAVE_SGI_STL_PORT
285 # define STL_IOSTREAM <iostream>
286 # define STL_ITERATOR <iterator>
287 # define STL_FSTREAM <fstream>
288 # define STL_STRING <string>
289 # define SG_NO_DEFAULT_TEMPLATE_ARGS
290 # define SG_NAMESPACES
291 // # define SG_HAVE_STD
293 # define SG_COMPILER "Borland C++ version " SG_STRINGIZE(__BORLANDC__)
295 #endif // __BORLANDC__
298 // Native SGI compilers
301 #if defined ( sgi ) && !defined( __GNUC__ )
302 # define SG_HAVE_NATIVE_SGI_COMPILERS
304 # define SG_EXPLICIT_FUNCTION_TMPL_ARGS
305 # define SG_NEED_AUTO_PTR
306 # define SG_MEMBER_TEMPLATES
307 # define SG_NAMESPACES
309 # define SG_CLASS_PARTIAL_SPECIALIZATION
310 # define SG_HAVE_TRAITS
312 # define STL_ALGORITHM <algorithm>
313 # define STL_FUNCTIONAL <functional>
314 # define STL_IOMANIP <iomanip.h>
315 # define STL_IOSTREAM <iostream.h>
316 # define STL_ITERATOR <iterator.h>
317 # define STL_FSTREAM <fstream.h>
318 # define STL_STDEXCEPT <stdexcept>
319 # define STL_STRING <string>
320 # define STL_STRSTREAM <strstream.h>
322 // # define __STL_FUNCTION_TMPL_PARTIAL_ORDER
323 // typedef void PFNGLPOINTPARAMETERFEXTPROC
325 #define glPointParameterfEXT glPointParameterfSGIS
326 #define glPointParameterfvEXT glPointParameterfvSGIS
328 #pragma set woff 1001,1012,1014,1116,1155,1172,1174
329 #pragma set woff 1401,1460,1551,1552,1681
332 #pragma set woff 1682,3303
335 # define SG_COMPILER "SGI Irix compiler version " SG_STRINGIZE(_COMPILER_VERSION)
337 #endif // Native SGI compilers
341 # include <strings.h>
343 # if defined ( __cplusplus )
344 // typedef unsigned int size_t;
346 extern void *memmove(void *, const void *, size_t);
349 extern void *memmove(void *, const void *, size_t);
350 # endif // __cplusplus
352 # define SG_COMPILER "Sun compiler version " SG_STRINGIZE(__SUNPRO_CC)
357 // Intel C++ Compiler
360 # define SG_NAMESPACES
362 # define SG_HAVE_STREAMBUF
363 # define SG_HAVE_TRAITS
364 # define SG_HAVE_STD_INCLUDES
366 # define STL_ALGORITHM <algorithm>
367 # define STL_FUNCTIONAL <functional>
368 # define STL_IOMANIP <iomanip>
369 # define STL_IOSTREAM <iostream>
370 # define STL_ITERATOR <iterator>
371 # define STL_FSTREAM <fstream>
372 # define STL_STDEXCEPT <stdexcept>
373 # define STL_STRING <string>
374 # define STL_STRSTREAM <strstream>
376 # define SG_COMPILER "Intel C++ version " SG_STRINGIZE(__ICC)
381 // No user modifiable definitions beyond here.
384 #ifdef SG_NEED_EXPLICIT
388 #ifdef SG_NEED_TYPENAME
392 #ifdef SG_NEED_MUTABLE
402 #ifdef SG_EXPLICIT_FUNCTION_TMPL_ARGS
403 # define SG_NULL_TMPL_ARGS <>
405 # define SG_NULL_TMPL_ARGS
408 #ifdef SG_CLASS_PARTIAL_SPECIALIZATION
409 # define SG_TEMPLATE_NULL template<>
411 # define SG_TEMPLATE_NULL
414 // SG_NO_NAMESPACES is a hook so that users can disable namespaces
415 // without having to edit library headers.
416 #if defined(SG_NAMESPACES) && !defined(SG_NO_NAMESPACES)
417 # define SG_NAMESPACE(X) namespace X {
418 # define SG_NAMESPACE_END }
419 # define SG_USING_NAMESPACE(X) using namespace X
421 # define SG_NAMESPACE(X)
422 # define SG_NAMESPACE_END
423 # define SG_USING_NAMESPACE(X)
426 /** \def SG_USING_STD(x)
427 * Expands to using std::x if SG_HAVE_STD is defined
430 # define SG_USING_STD(X) using std::X
433 # define SG_USING_STD(X)
437 // Additional <functional> implementation from SGI STL 3.11
438 // Adapter function objects: pointers to member functions
439 #ifdef SG_INCOMPLETE_FUNCTIONAL
441 template <class _Ret, class _Tp>
442 class const_mem_fun_ref_t
444 : public unary_function<_Tp,_Ret>
445 #endif // __BORLANDC__
448 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
449 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
451 _Ret (_Tp::*_M_f)() const;
454 template <class _Ret, class _Tp>
455 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
456 { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
458 #endif // SG_INCOMPLETE_FUNCTIONAL
461 * SG_STATIC_CONSTANT workaround.
462 * On compilers which don't allow in-class initialization of static integral
463 * constant members, we must use enums as a workaround if we want the constants
464 * to be available at compile-time. This macro gives us a convenient way to
465 * declare such constants.
467 #ifdef SG_NO_INCLASS_MEMBER_INITIALIZATION
468 # define SG_STATIC_CONST(type,assignment) enum { assignment }
470 # define SG_STATIC_CONST(type,assignment) static const type assignment
473 #endif // _SG_COMPILER_H